Cannot get cron to work on Amazon EC2? Cannot get cron to work on Amazon EC2? unix unix

Cannot get cron to work on Amazon EC2?


Cron can be run in Amazon-based linux server just like in any other linux server.

  1. Login to console with SSH.
  2. Run crontab -e on the command line.
  3. You are now inside a vi editor of the crontab of the current user (which is by default the console user, with root permissions)
  4. To test cron, add the following line: * * * * * /usr/bin/uptime > /tmp/uptime
  5. Now save the file and exit vi (press Esc and enter :wq).
  6. After a minute or two, check that the uptime file was created in /tmp (cat /tmp/uptime).
  7. Compare it with the current system uptime by typing the uptime command on the command line.

The scenario above worked successfully on a server with the Amazon Linux O/S installed, but it should work on other linux boxes as well. This modifies the crontab of the current user, without touching the system's crontabs and doesn't require the user inside the crontab entry, since you are running things under your own user. Easier, and safer!


Your cron daemon is not running. When you're running ps aux | grep crond the result is showing that only the grep command is running. Be aware of this whenever you run ps aux | grep blah.

Check the status of the cron service by running this command.

Try:

sudo service crond status

Additional information here: http://www.cyberciti.biz/faq/howto-linux-unix-start-restart-cron/.


On some AWS Ubuntu EC2 machines, cron jobs cannot be edited or made to run by using crontab -e or even sudo crontab -e (for whatever reason). I was able to get cron jobs working by:

  1. touch /home/ubuntu/crontest.log to create a log file
  2. sudo vim /etc/crontab which edits the system-wide crontab
  3. add your own cron job on the second to last line using the root user, such as * * * * * root date && echo 'It works!'>> /home/ubuntu/crontest.log 2>&1 which dumps stdout and stderr into the logfile you created in step 1
  4. Verify it is working by waiting 1 minute and then cat /home/ubuntu/crontest.log to see the output of the cron job