【发布时间】:2019-02-11 07:28:29
【问题描述】:
我正在尝试在 python 中找出节点上的孤立文件。 下面是代码sn-p
#!/usr/bin/python
import subprocess
try:
s = subprocess.check_output(["find", "/", "-fstype", "proc", "-prune", "-o", "\( -nouser -o -nogroup \)", "-print"])
except subprocess.CalledProcessError as e:
print e.output
else:
if len(s) > 0:
print ("List of Orphan Files are \n%s\n" % s)
else:
print ("Orphan Files does not Exists on the NE")
当我尝试运行这个 python 代码时
> python test.py
find: paths must precede expression: \( -nouser -o -nogroup \)
Usage: find [-H] [-L] [-P] [-Olevel] [-D help|tree|search|stat|rates|opt|exec] [path...] [expression]
当我在 CLI 上运行相同的命令时,它工作正常。
> find / -fstype proc -prune -o \( -nouser -o -nogroup \) -print
/root/a
很少有人建议使用 shell=true,因为子进程的 python 文档是安全隐患。
Warning Using shell=True can be a security hazard.
【问题讨论】:
标签: python linux subprocess