Preventing cron to go crazy

I just realized an issue where a cron that was scheduled to run every minute – just went crazy and launched few hundred processes which let the server die up. Seems like the previous cron hadn’t completed execution and the other one kicked off. Good feedback from a fellow member to check the number of process running before executing a job – which is as easy as grep’ing the process and checking the count

count=`ps -ef | grep wget | grep -v grep | wc -l`
#echo $count
if [ $count -lt 1 ]; then
#echo ‘No current wget in execution. Start wget cron’
wget http://server-name/job-name
fi

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s