2

I have been trying for a while now to setup a cron job on EC2 at no luck at all. Although the cron job is listed and runs, it just doesn't find the file.

Here is the cron job

*/5 * * * * python /home/ec2-user/monitoring/job.py  >> /var/log/script_output.log 2>&1
Barmar
  • 741,623
  • 53
  • 500
  • 612
Mostafa Mahmoud
  • 570
  • 5
  • 13

1 Answers1

4

It seems what we've got here is one of those rare cases when cron job doesn't run.

Here's how I would tackle this problem.

  • I would run python /home/ec2-user/monitoring/job.py >> /var/log/script_output.log 2>&1 in bash. Just to check that the command can run in normal circumstances.

  • I would add MAILTO=your@email. Just to get emails when something goes wrong.

  • I would run which python command and use full path to python in the cron file. Let's say which python returned /usr/bin/python. Then I would edit cron file like this: */5 * * * * /usr/bin/python /home/ec2-user/monitoring/job.py >> /var/log/script_output.log 2>&1

  • I would append an empty line to the cron file. Actually I would do this first. But I'm stuck on FreeBSD's default cron. You're probably running Ubuntu and using Vixie Cron. Couldn't hurt anyway.

  • I would run pgrep cron in bash. Just to check that cron daemon is well and running.

In the end your cron should look like this:

MAILTO=my@email.com

*/5 * * * * /usr/bin/python /home/ec2-user/monitoring/job.py >> /var/log/script_output.log 2>&1
Community
  • 1
  • 1
Nigel Tufnel
  • 11,146
  • 4
  • 35
  • 31