Ubuntu Server init.d - testing if value is greater than 1
I am writing an init.d script and am looking to test if a returned value is greater than 1. What would be the correct syntax for 'greater than'?
mc_status() {
if ps ax | grep -ci 'CanaryMod.jar' > 0
then
echo "$SERVICE is running."
else
echo "$SERVICE is not running."
fi
}
开发者_C百科
From my recollection init scripts are written in the sh shell. Many shell scripts use a pid file (usually found in /var/run) to check if a service is running. In your case a process as found in ps is used for validation.
The test you are performing is somewhat incorrect, as ps/grep are returning not a number but a set of characters or nothing. Try the following:
mc_status() {
if [ ! -z "`ps ax | grep -ci 'CanaryMod.jar'`" ]; then
echo "$SERVICE is running."
else
echo "$SERVICE is not running."
fi
}
精彩评论