2013-04-04 100 views
0

如果兩個進程未運行,如何檢入「if」條件?檢查兩個進程是否未在shell腳本中運行

我用

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 

任何人有任何好的建議,我可以檢查,如果只要求兩個過程「而不是」運行

感謝

回答

1
ps -aux |grep -v <process name> 

-v是「逆匹配',IOW,當你正在尋找的物品不匹配時它會返回成功

+0

如何在if條件中使用它來檢查進程是否「不」運行? – JumpOffBox 2013-04-04 17:01:00

2
if [ $(ps aux | grep -E "(processName1|processName2)" | grep -v grep | wc -l) -eq 0 ] 
then 
    echo "not running" 
fi 
相關問題