1 | #
|
---|
2 | # Python Cron
|
---|
3 | # by Emilio Schapira
|
---|
4 | # Copyright (C) 2003 Advanced Interface Technologies, Inc.
|
---|
5 | # http://www.advancedinterfaces.com
|
---|
6 | # http://sourceforge.net/projects/pycron/
|
---|
7 | #
|
---|
8 |
|
---|
9 | **
|
---|
10 | ** INTRODUCTION
|
---|
11 | **
|
---|
12 |
|
---|
13 | This is a clone of the well-known cron job scheduler for the unix flavored
|
---|
14 | operating systems. It is implemented in Python. The main motivation for the
|
---|
15 | project is to provide a robust cron daemon for the Microsoft Windows*
|
---|
16 | operating system. However, Python Cron is platform-independant, and can
|
---|
17 | be used on any operating system that supports python.
|
---|
18 |
|
---|
19 | CygWin (http://www.cygwin.com/) provides a robust implementation of the cron
|
---|
20 | daemon, however it requires installing the full cygwin package. There are
|
---|
21 | currently other alternatives that are either not robust, not free or not
|
---|
22 | open source. Examples of these alternatives are WinCron
|
---|
23 | (http://www.wincron.co.uk/), Cron (http://www.kalab.com/freeware/cron/cron.htm).
|
---|
24 |
|
---|
25 | This implementation is very simple, complete and robust.
|
---|
26 |
|
---|
27 | **
|
---|
28 | ** USAGE
|
---|
29 | **
|
---|
30 |
|
---|
31 | usage: cron [crontab_file_name [log_file_name [pid_file_name]]]
|
---|
32 |
|
---|
33 | crontab_file_name Name and location of the crontab file. By
|
---|
34 | default it is ./crontab
|
---|
35 | log_file_name Name and location of the log file. By default
|
---|
36 | it is ./cron.log
|
---|
37 | pid_file_name Name and location of the pid file. This file
|
---|
38 | will contain the process id of the cron
|
---|
39 | process. It can be used later to stop the cron
|
---|
40 | file. By default it is ./cron.pid
|
---|
41 |
|
---|
42 | **
|
---|
43 | ** Crontab files
|
---|
44 | **
|
---|
45 |
|
---|
46 | A contrab file contains one command per line, except empty lines and
|
---|
47 | lines starting with the character #, which are considered as comments.
|
---|
48 | This file will be scanned every minute when cron is running.
|
---|
49 |
|
---|
50 | Each command has the format:
|
---|
51 |
|
---|
52 | <minute> <hour> <day of month> <month> <day of week> <command> <args>
|
---|
53 |
|
---|
54 | Cron will scan each entry and match the first five values with the
|
---|
55 | current local time and date. The entries for each of these values must
|
---|
56 | be either:
|
---|
57 |
|
---|
58 | - A number. For <month> it is the month number, and for <day of week>
|
---|
59 | is the day number starting with Sunday=0.
|
---|
60 | - An asterisk (*) which indicates that any value matches this field.
|
---|
61 | - Comma separated numbers that indicate that each of the values can
|
---|
62 | match this field.
|
---|
63 |
|
---|
64 | The 6th argument, <command>, is the name of the program to run. The remaining
|
---|
65 | arguments are passed to the programm <command> as command-line arguments.
|
---|
66 |
|
---|
67 | Example cron entries
|
---|
68 |
|
---|
69 | 0 * * * * echo "run every hour"
|
---|
70 |
|
---|
71 | 0 3 * * * echo "run every day at 3am"
|
---|
72 |
|
---|
73 | 30,0 * * * * echo "run every half hour"
|
---|
74 |
|
---|
75 | 45 15 * * 1 echo "run every monday at 3:45pm"
|
---|
76 |
|
---|
77 | 0 4 15 * * echo "run on the 15th of every month at 4am"
|
---|
78 |
|
---|
79 | **
|
---|
80 | ** Windows
|
---|
81 | **
|
---|
82 |
|
---|
83 | This example is for Windows 2K.
|
---|
84 |
|
---|
85 | 1.- Unzip the package in c:\Program Files\pycron.
|
---|
86 |
|
---|
87 | 2.- You can create a shorcut in the startup folder, with
|
---|
88 | the following properties:
|
---|
89 |
|
---|
90 | Target = C:\Program Files\Python22\pythonw.exe C:\Program Files\pycron\cron.py
|
---|
91 | Start In = C:\Program Files\pycron
|
---|
92 |
|
---|
93 | You will notice that console processes are launched in a new console window.
|
---|
94 | To avoid this, use the provided program silentstart in your crontab file. For
|
---|
95 | example:
|
---|
96 |
|
---|
97 | # Run backup script every morning at 3am
|
---|
98 | 0 3 * * * silentstart c:\scripts\backup.bat
|
---|
99 |
|
---|
100 | silentstart.exe must be in the path. You can copy it to c:\winnt\system32.
|
---|
101 |
|
---|
102 | **
|
---|
103 | ** Limitations
|
---|
104 | **
|
---|
105 |
|
---|
106 | - Crontab files can not have environment variable definitions.
|
---|
107 | - pycron doeas not support the expresions of the form /2, month
|
---|
108 | or day of the week names, or dash expresions such as 5-9.
|
---|
109 |
|
---|