AWS Instance with cron job

This example show how to create a cron job that usually require with sudo command. Let’s say I’d like to ensure mysqld instance is restart when the service is stopped.

Root Crontab

[ec2-user@xxxxx ~]$ sudo crontab -e


Check Script

* * * * * /home/ec2-user/


MySqlCheck Script


if (( $(ps -ef | grep -v grep | grep $service | wc -l) > 0 ))
echo "$service is running!!!"
/etc/init.d/$service start





AWS Instance with cron job

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.