Cron originated in the Unix environment. It is a job scheduler, allowing scripts to be run automatically at a certain time or date. The name was based on the Greek word for time, chronos.
The Uniform Servers portable Cron plugin has been integrated into Uniform Server Zero. Cron's configuration file has been pre-populated with various scripts to be run. These are essentially four-line templates that require enabling to run the appropriate applications from the Cron script.
The Uniform Server Zero provides a simple user control interface to start and stop Cron.
- Configuration file pre-configured for common applications.
- Run Cron as a standard program.
- Run scripts with the following file extensions: .bat, .vbs and .php
- Pre-configured to run Moodle and Drupal cron jobs.
Each script to be run requires a configuration entry in the configuration file cron.ini. Open this file in the default editor using UniController as follows:
Extra > Cron
- Each script to be run requires a configuration block. On the right, three examples are shown.
- Command-line scripts (.bat, .vbs and .php) require either an absolute or relative path (including script's file name) to be specified.
◦ Note: For portability, a relative path is specified.
This path is relative to folder UniServerZ, e.g. \home\us_cron\test\test_cron_1.bat
◦ Note: Scripts with a .vbs extension are run using the Cscript.exe engine.
These scripts shall not use any GUI interfaces.
- Web-applications require a URL path. This URL path is what you would type into a browser to run that script.
;start = 0000-00-00 2:10:00
;period = hourly
;path = http://localhost/moodle/admin/cron.php
;start = 0000-00-00 2:30:00
;period = hourly
;path = http://localhost/drupal/cron.php
;start = 0000-00-00 23:35:00
;period = 10
;path = C:\UniServerZ\home\us_cron\test\test_cron_1.bat
Configuration block format
Each script running a Command-line or Web-application is defined in a separate block with the following format:
||Each block starts with a unique name enclosed in square brackets. Note that no spaces are allowed.
|| Initial start time with the following format: Y-M-D H:M:S - Note: 24-hour clock.
||How often to run the script from the above referenced start time.
Values: hourly, daily, weekly, monthly or numeric in seconds.
a) For a web application, the full URL of the script, e.g. http://localhost/drupal/cron.php
b) Command-line (CLI) option 1: Use an absolute path with back-slashes, e.g. C:\UniServer\uni_con\cron\test_cron_1.bat
c) Command-line (CLI) option 2: Use a relative path with back-slashes, e.g. \home\us_cron\test_cron_1.bat
||A timestamp updated by cron script. Set initial value to blank.
||Cron automatically updates ref. It initially adds period as set above to Start time.
For subsequent runs, it sets ref to current time + period.
||To change start time, first set a new value for start and delete the ref number, then save the file.
The script will run at the new date and time set, and thereafter at the rate you defined for period.
||To use pre-configured web blocks for Moodle and Drupal, uncomment to enable.
||Command-line paths starting with "\" followed by sub-folders below UniServerZ are portable.
Paths outside UniServerZ are not portable and require manually changing after relocating Uniform Server Zero.
The Uniform Server Zero provides a simple user control interface to start and stop Cron. Open this controller as follows:
Extra > Cron
The Cron Controller consists of two buttons and two check boxes shown on the right.
- Edit configuration file button (1) opens the configuration file in Notepad.
- View log file button (2) opens the Cron log file in Notepad.
- Run Cron (3) - Clicking this check box toggles between two states, checked and unchecked, which starts and stops Cron respectively.
- Cron logging (4) - Clicking this check box toggles between two states, checked and unchecked, which enables and disables Cron logging respectively.
Note: Initially, both Run Cron (3) and Cron logging (4) check boxes are unchecked.
Cron logs the following information:
- Time Cron was started.
- Start time and path of a script that is run.
- Time Cron was stopped. Note: if this is missing from the log, it means UniController was not closed before the PC was turned off.
Note: Cron logging is disabled by default.
Cron, run and logging are disabled by default. Instead of using the Cron controller covered above, you can directly edit the server configuration file.
To enable both Cron running and logging, proceed as follows:
- Open user configuration file: UniServerZ\home\us_config\us_config.ini
- Locate section [CRON] shown on right.
- Set enable_cron to true.
- Set cron_logging to true.
; Run Cron
; true - Run Cron
; false - Disable (stop) Cron (default)
; Cron logging
; true - Enable logging
; false - no logging (default)
Four test files have been included and pre-configured in Cron's configuration file.
The following three scripts are simple command-line script creating a text file when run:
- UniServerZ\home\us_cron\test\test_cron_1.bat - File created: UniServerZ\home\us_cron\test\test_cron_1_bat_result.txt
- UniServerZ\home\us_cron\test\test_cron_2.vbs - File created: UniServerZ\home\us_cron\test\test_cron_2_vbs_result.txt
- UniServerZ\home\us_cron\test\test_cron_3.php - File created: UniServerZ\home\us_cron\test\test_cron_3_php_result.txt
Copy the fourth script UniServerZ\home\us_cron\test\cron_test.php to root folder UniServerZ\www - File created: UniServerZ\www\us_cron_test_4.txt
The above has shown how easy Cron is to use and configure.