我想将shell命令输出与使用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:
#matchedtest1.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发布于 2021-01-17 00:10:59
lines2 = file_read.read()第二次调用file_read.read()将返回空。您应该在循环外调用,并将结果存储在一个可在循环内使用的变量中。
https://stackoverflow.com/questions/65751613
复制相似问题