In the performance of IT tasks, we have encountered problems and limitations with the Windows Task Scheduler when trying to use it to run batch files on a schedule. It is not reliable and its capabilities are limited.
We were searching online for a free replacement for the Task Scheduler when we came across Pycron. Being users of Linux for programming and performing nightly builds of our software, we were intrigued by software for Windows that emulates the Cron utility in Linux. We use the Cron utility to schedule our nightly builds on our Linux build server and it is very reliable and flexible.
NOTE: Your version of Windows needs to support services in order to use pycron. You also need administrative rights to install the software and stop and start services.
Download pycron at http://www.kalab.com/freeware/pycron/pycron.htm.
When the installation is done, be sure to select the option to install as a service before you click Finish.
If you don’t have any tasks scheduled, you do not need to stop the Task Scheduler service. However, it is easy to do and ensures no conflicts between the Task Scheduler and pycron.
To stop the Task Scheduler service, select Control Panel | Administrative Tools | Services from the Start menu.
Scroll down to Task Scheduler, right-click on the service name and select Properties.
Select Manual from the Startup type drop-down list.
Click Stop under Service status to stop the service. Click Apply and then click OK.
Scroll to Python Cron Service, right-click on the name of the service, and select Properties.
Click the Start button under Service status to start the service and then click OK.
Select File | Exit on the Services dialog box to close it.
Pycron uses a file called crontab.txt to store scheduled entries. This file must reside in the directory in which pycron was installed, most likely C:\Program Files\pycron, if you did not change the location during the installation.
You can create the file manually to be loaded in the editor; however, this is not necessary. For this example, you will create the entries directly in the crontab editor.
To start the editor, select Programs | pycron | crontab.txt Editor from the Start menu.
The parameters of a crontab entry from left to right are as follows.
|Minute||Hour||Day of Month||Month||Week Day||Task|
(0 For Mon, and 6 for Sunday – You may also use names.)
|Command/Application to execute and the parameter to the Command/Application.
(separate the two values with a space when editing the crontab.txt file directly)
To create a new entry, select New from the Item menu.
The Task Properties dialog box displays.
As an example entry, we will set up a task to backup a set of files in one directory to another directory every 3 hours, Monday through Friday, between the hours of 9:00 AM to 6:00 PM, for all the months of the year. The work files are in C:\MyWork and the backup files are to be copied to C:\MyBackup.
Click the Browse button next to the Command edit box and select xcopy.exe from your system32 directory within the Windows directory.
In the Parameters edit box enter the following text, specifying the source and destination directories and an option for xcopy.exe:
C:\MyWork\* C:\MyBackup /Y
The /Y option suppresses prompting to confirm you want to overwrite an existing destination file. This way the copying of the files can occur without intervention from you.
Always test your command by clicking the Test execution button to make sure your command is valid. If all was successful, you will see your command/application run and a dialog box displays indicating the execution was successful.
Enter the following values:
- For Minute: 0
- For Hour: 9-18/3 (“18” indicates the military time for 6 PM and the “/3” indicates every third hour)
- For Day: *
- For Month: *
- For Week Day: 0-4
The crontab editor should look like the following picture:
To save this entry, select Save from the File menu.
NOTE: You can also set up pycron to run custom batch files containing a series of commands. You can also run other programs.
An example crontab file is provided in the directory in which pycron was installed called crontab.txt.sample. You may use that file as an initial crontab file (copy it to a file called crontab.txt) or just as a reference on how to set up cron jobs.
There are also descriptions of how to use the parameters in the crontab.txt file. For more details on the Cron utility, see http://www.linuxhelp.net/guides/cron/.
by Lori Kaufman