I have written a shell script in order to monitor Nagios service status continuously (See this question), which is as follows:
#!/bin/bash RCPT="firstname.lastname@example.org" service nagios status | grep [0-9] if [ $? -eq 0 ] then exit 0 else service nagios start echo "Hello, Nagios Service has been started, please confirm." | mail -s "Nagios Service Stopped" $RCPT fi
When above script is executed from command-line, it would work as expected - it would send an email if PID is not found in the service status output, else exits. But, when I added this script in
crontab, it would dispatch a notification every time it is executed.
What might be the problem and how to overcome it?