i'm trying to check if a program on a linux server is running and start it if not. But i get strange errors:
#!/bin/sh SERVICE=nrpe ps -ef | grep -v grep | grep $SERVICE | wc -l if [ $? -gt 1 ] then echo "$?" echo "$SERVICE service running, everything is fine" else echo "$?" echo "$SERVICE is not running" service $SERVICE start fi
The Output is:
[root@mail ~]# check_nrpe.sh 2 1 nrpe is not running Starting Nagios NRPE daemon (nrpe):
It is the same Message whether nrpe is running or not.
If I test the command
ps -ef | grep -v grep | grep $SERVICE | wc -l in shell, it works.