Wednesday, March 24, 2010

PCron ---- portable cron :)

PCron

Cron for Windows & ... :)

Cron is basically a job scheduler available in Linux and its variants/flavors.
I have tried to implement the functionality of Cron in Python so that it can be used in Windows and ....

You should have Python 2.5 + installed to use this.

Input for PCron is a plain text file (lets' call it pcrontab) with syntax/format similar to *nix crontab. pcrontab can have formats such as -> */12 and 12-20
Here is an example of a pcrontab:
*/5 * * * * F:\Program Files (x86)\K-Lite Codec Pack\Media Player Classic\mpc-hc.exe
57-59 18 * * * F:\Program Files (x86)\Calc.exe

In above example, first line instructs PCron to start the program mpc-hc.exe every 5 minutes.
And the second line instructs PCron to start the program Calc.exe on 18:57, 18:58, 18:59

To understand more on the syntax of pcrontab ... look at the picture below which explains about crontab ->
Usage:
python pcron.py --taskfile
Examples:
python pcron.py --taskfile c:\\pcrontab.txt
python pcron.py --taskfile /home/vikas/pcrontab
Currently it writes out logs to stdout, so you have to redirect it ... to say /dev/null or a file

Limitations:
Each time you add an entry into the pcrontab, you have to restart the script or wait until the script reloads the pcrontab (it reloads in every 5 minutes ~)
Does not support entire format/syntax combinations as compared to crontab

More things to come:
An editor for pcrontab ... that would detect changes in pcrontab and initiates automatic reload in pcron
Support for a timeout field in pcrontab, which enables us to run a program for a certain period of time

You can download the scripts from here:
TimedPopenNT
Scheduler
pcron

On Windows you can generate a .exe file using py2exe and use that as standalone instead of the script.

0 comments: