cronjob now working - huwenyuan/Linux GitHub Wiki
The script (watchdog-TSY.sh):
#!/bin/sh
allPsRun=1
outputFile=/usr/cad/watchdog/error.log
#check whether all processes are running
echo =============== `date` ================
ps cax | grep SNMP-Receiver > /dev/null
if [ $? -eq 0 ]; then
echo "SNMP-Receiver is running."
else
echo `date` "SNMP-Receiver is not running." >> $outputFile
fi
...
Run crontab -e
, the result is
*/2 * * * * nms /bin/sh /usr/cad/watchdog/watchdog-TSY.sh
Open /var/log/cron
, the log showing:
Jan 27 01:00:00 localhost CROND[7930]: (nms) CMD (nms /bin/sh /usr/cad/watchdog/watchdog-TSY.sh)
That means the cronjob is running, but the script failed to run because there is no new data in file error.log
. Modified the crontab -e
, and removed "nms" then it works. The new crontab -e
is:
*/2 * * * * /bin/sh /usr/cad/watchdog/watchdog-TSY.sh