JumpOffBox
JumpOffBox

Reputation: 783

Checking whether two processes are not running in shell script

How do I check in an "if" condition if two processes are not running ?

I have used

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

Anyone has any good suggestion where I can check if only required two processes are "not" running

Thanks

Upvotes: 0

Views: 195

Answers (2)

Alex
Alex

Reputation: 11090

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

Upvotes: 2

KevinDTimm
KevinDTimm

Reputation: 14376

ps -aux |grep -v <process name> 

-v is 'inverse match', IOW, it returns success when the item you're looking for does not match

Upvotes: 1

Related Questions