0
votes

Am new to Unix and was trying to add a cron job which should run a python script at the 0, 15, 30, 45th min of every hour. I ran this command, crontab -e, and added following four lines to the end of the file,

0 * * * * /usr/bin/python /var/www/test.py
* 15 * * * /usr/bin/python /var/www/test.py
* * 30 * * /usr/bin/python /var/www/test.py
* * * 45 * /usr/bin/python /var/www/test.py

I did run, /usr/bin/python /var/www/test.py from my home directory and it runs fine. But never gets kicked off by cron. I also ran the following command,

ps aux | grep cron

to make sure cron is running and from the output seems like it is.

Ubuntu version: 12.04.4 LTS

Any ideas why the cron jobs never get run?

Thanks

1

1 Answers

2
votes

To run every 15 minutes, you need:

*/15 * * * * /usr/bin/python /var/www/test.py

Your current syntax is incorrect, and is trying to run the job on the hour, again at 3pm, again on the 30th of the month and finally on the 45th month of the year (invalid).

* * * * *  command to execute
┬ ┬ ┬ ┬ ┬
│ │ │ │ │
│ │ │ │ │
│ │ │ │ └───── day of week (0 - 7) (0 to 6 are Sunday to Saturday, or use names; 7 is Sunday, the same as 0)
│ │ │ └────────── month (1 - 12)
│ │ └─────────────── day of month (1 - 31)
│ └──────────────────── hour (0 - 23)
└───────────────────────── min (0 - 59)

Finally, always make sure that the final line in the crontab is terminated with a newline - failure to do so will prevent the last command running.