如果两个进程没有运行,如何检查“if”条件?
我用过
if [ `pgrep <process name>`] does not work with ot without square brackets
using ps -aux |grep <process name> in if condition does not work, since every time
grep <process name>
is up and it will always pass
任何人都有任何好的建议,我可以检查是否只需要两个进程“没有”运行
谢谢
答案 0 :(得分:2)
if [ $(ps aux | grep -E "(processName1|processName2)" | grep -v grep | wc -l) -eq 0 ]
then
echo "not running"
fi
答案 1 :(得分:1)
ps -aux |grep -v <process name>
-v是'反向匹配',IOW,当您要查找的项目不匹配时它返回成功