Danny Moss
Danny Moss

Reputation: 85

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

Upvotes: 2

Views: 1613

Answers (2)

avasal
avasal

Reputation: 14864

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)

Upvotes: 5

Amadan
Amadan

Reputation: 198436

crontab -e, and insert these:

0 0 * * 1 /srv/django/get_rankings.py
0 5 * * 1 /srv/django/get_rankings.py

0 0 is midnight; 0 5 is 05:00am. 1 is Monday. The two stars mean "I don't care about the date". Here is a good reference.

You can put it all in one line by saying "0 o'clock or 5 o'clock":

0,5 0 * * 1 /srv/django/get_rankings.py

Upvotes: 1

Related Questions