[Solved] Help with condition

I have below code, I am checking on one server where ppp.sh process not running it is perfectly fine, when i am checking the same script on another server where ppp.sh script is running, it is throwing error "too many arguments", how to avoid this. If i will check on server where process running it shows "ppp process running" and if i will check on server where process not running it shows error "ppp process stop"


count=$(ps -ef | grep ppp.sh | grep -v grep)

if [ ${count:-0} -ge 2 ]
then
echo "PPP process running "
else
echo "PPP process stop "
fi

I think you meant to count the lines.

count=$(ps -ef | grep ppp.sh | grep -v grep| wc -l)

Not sure about your variable count . If you want to avoid error getting displayed, then you can redirect to /dev/null and you can check exit status $? , where exit code 0 is true and 1 is false.

Or, using one less process:

count=$(ps -ef | grep ppp.sh | grep -cv grep)

Thanks so much for your help, problem solve.

With the [ ] trick grep does not find its own args

count=$(ps -ef | grep -c "[p]pp.sh")

A perhaps more precise match is

count=$(ps -ef | grep -wc "[p]pp\.sh")