Thursday, April 12, 2012

Python Script vs Cron Job

I need to run a cron job to generate a list of user rankings each week at exactly "00:00:00" UTC each Monday morning. Has anyone got an example for this, it's really doing my head in ... I looked into "crontab -e" and was instantly lost.


Basics:
  - Run the script, eg: /srv/django/get_rankings.py
  - Run the script at "00:00:00" and "00:05:00" every Monday.
  - Run the same script the next Monday ... and repeat
 


I'm on Linux Arch, any heads up would be amazing.


Thanks so much,
Hope all is well



Answer:


crontab put entry like,

00,05 0 * * 1 /srv/django/get_rankings.py

runs the script at 00.00 & 00.05 every Monday of every month

*     *     *   *    *        command to be executed-     -     -   -    -
|     |     |   |    |
|     |     |   |    +----- day of week (0 - 6) (Sunday=0)
|     |     |   +------- month (1 - 12)
|     |     +--------- day of        month (1 - 31)
|     +----------- hour (0 - 23)
+------------- min (0 - 59)
* in the value field above means all legal values as in braces for that column. The value column can have a * or a list of elements separated by commas.
An element is either a number in the ranges shown above or two numbers in the range separated by a hyphen (meaning an inclusive range)

No comments:

Post a Comment