[英]python : compare a text with file
我想将 shell 命令 output 与使用 python 的文本文件进行比较,这是我的代码:
os.system('find / -perm -u=s -type f 2>/dev/null')
suid_file = open("suid_list.txt", "r")
os.system('find / -perm -u=s -type f 2>/dev/null > /tmp/test1.txt')
lines = suid_file.read().split(',')
lines2 = open('/tmp/test1.txt', 'r').read()
for y in lines:
if y in lines2:
#matched
而test1.txt的内容是:
/usr/bin/su
/usr/bin/bwrap
/usr/bin/chsh
/usr/bin/ntfs-3g
/usr/bin/kismet_cap_ti_cc_2540
/usr/bin/mount
/usr/bin/vmware-user-suid-wrapper
/usr/bin/passwd
/usr/bin/fusermount3
/usr/bin/kismet_cap_linux_bluetooth
/usr/bin/kismet_cap_nxp_kw41z
/usr/bin/kismet_cap_nrf_mousejack
/usr/bin/newgrp
/usr/bin/gpasswd
lines2 = file_read.read()
file_read.read() 的第二次调用将返回空。 您应该在循环外部调用并将结果存储在一个可以在循环内部使用的变量中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.