I have written up the following script
#! /bin/bash
function checkIt()
{
ps auxw | grep $1 | grep -v grep > /dev/null
if [ $? != 0 ]
then
echo $1"bad";
else
echo $1"good";
fi;
}
checkIt "nginx";
checkIt "mysql";
checkIt "php5-fpm";
The problem here appears to be with the last check checkIt "php5-fpm"
which consistently returns php5-fpmbad. The trouble appears to arise due to the hyphen. If I do just checkIt "php5"
I get the expected result. I could actually get away with it since I do not have any other process that starts with or contains php5. However, it turns into a hack that will rear up its ugly head one day. I'd be most grateful to anyone who might be able to tell me how to get checkIt "php5-fpm" to work.
The normal way to check if service is running or not in *nix is by executing this:
/etc/init.d/servicename status
e.g.
/etc/init.d/mysqls status
These scripts check status by PID rather than grepping ps output.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With