1825719 Members
2965 Online
109686 Solutions
New Discussion

Monitoring cron daemon

 
SOLVED
Go to solution

Monitoring cron daemon

Hi,

I need some help writing a script to start my cron if its not running.It falls over once a month which causes alot of problems.Plain & simple script to start /sbin/rc2.d/S70CRON start
6 REPLIES 6
Peter Godron
Honored Contributor

Re: Monitoring cron daemon

spex
Honored Contributor
Solution

Re: Monitoring cron daemon

Hi,

# cat croncheck.sh

#!/usr/bin/sh
while true
do
if [[ $(UNIX95= ps -H -C cron -o pid= | wc -l) -lt 1 ]]
then
echo "cron restarted:\n$(date)" | mailx -m -s "cron restarted!" root
/sbin/init.d/cron start
fi
sleep 120
done
exit

Change 120 (2 minutes) to whatever interval you wish. For obvious reasons, you cannot schedule this script to run via cron. Instead, use 'nohup':

# nohup croncheck.sh > /dev/null 2&>1 &

PCS

Re: Monitoring cron daemon

Thank you Spex..The script is working like da bomb.i have assigned it to sms me & its like a dream for me.thank you
Peter Godron
Honored Contributor

Re: Monitoring cron daemon

Hi,
so you did not like the:
MYPROC=sendmail
COUNT=$(UNIX95=1 ps -C $MYPROC -o pid= -o args= | wc -l)
if [ $COUNT -lt 1 ]
then
/sbin/init.d/$MYPROC start
fi

example in the second link given?

Change the sendmail to cron and you had your solution.

Re: Monitoring cron daemon

No yours works just as well.Because Rex had his on i just copied it & pasted it instead of going to your link.I have tested yours as well & its excellent.Great job by you guys..i can see that i will be learning alot from yous.thank you

Re: Monitoring cron daemon

Problem soterd out.Thanx to you guys for the excellent support