nnCron LITE
[From the author's notes]
About nnCron LITE
Program Overview
nnCron LITE is a small, but full-featured scheduler that can start applications and open documents at specified time or with specified frequency. nnCron LITE is a perfect Windows clone of a well-known UNIX scheduler Cron (including all the useful Anacron features).
nnCron LITE is distributed as freeware application (see License).
Here are the most important features of nnCron LITE:
- It can be started as a system service or as a regular standalone application
- It understands cron table format (Unix) and is managed with easy-to-edit text crontab files that are fully compatible with Unix crontabs
- It can handle and restart so called missed tasks
- It can set and use environment variables
- It can run applications authorized as currently logged user (WinNT/2000/XP)
- It can be extended with plugins written in Forth language
- It can be easy tuned up to answer your current needs
- It is not resource demanding, and it can run even on very old PCs without any noticeable performance degradation. (We have never seen nnCron LITE service to allocate more than 150k of operative memory.)
nnCron LITE is tiny, powerful and easy to use. And if you need not just a scheduler, but a full-blown automation manager, take a look at nnCron.
Installing and Removing nnCron LITE
To start nnCron LITE installation, double-click on the distribution file with your left mouse button. During the installation you will be asked to select the installation folder.
Installation does not change any Windows system settings. All the files will be copied only to the folder you selected (except for the shortcuts which are automatically created in nnCron LITE program group of Windows Start menu).
In Win9?/ME, nnCron LITE creates an entry in the registry (HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run) in the course of installation so that it starts automatically on the system startup. You can view and/or edit the list of your startup programs with the poorly documented Windows utility msconfig.exe. In WinNT/2000/XP nnCron LITE is started as a system service (cron) on system startup - see Starting and Stopping nnCron LITE.
In order to modify properties of a service, use Services dialog available under Administrative Options in Windows Control Panel. If you wish to remove the installed nnCron LITE service, run uninstall_svc.bat in the program's home directory (it won't uninstall the application itself). You can also start nnCron LITE without starting the service. In order to do that, use "-ns" key in the command line. To install nnCron LITE service again, run install_svc.bat in the program's home directory.
The most convenient way to manually start nnCron LITE service is to run batch file startcron.bat. To unload nnCron from the computer memory you can run stopcron.bat.
You can find shortcuts to all of the above-mentioned batch files in nnCron LITE program group located in Windows Start menu.
To uninstall nnCron LITE, go to Add or remove programs in the Control Panel. When updating nnCron LITE to a newer version, you don't have to uninstall the previous installation - you can install new version right over the previous one. nnCron LITE's settings are stored in cron.ini file, and the tasks themselves in crontab files. Keep these files when re-installing or updating nnCron LITE or your operating system so that you don't have to fine-tune the program all over again. (See these notes for details).
Working with nnCron LITE
Crontab file cron.tab
Crontab File Syntax
The "heart" of nnCron LITE is a crontab file where all the data required to start an application is stored: starting time, frequency of its execution, application's name and parameters with with it should be run. Immediately after nnCron LITE is installed, a crontab file named cron.tab will be created in nnCron's installation directory. cron.tab is an ordinary text file. It can be created and/or edited in any available text editor.
Each minute, nnCron LITE checks time of last modification of cron.tab; if it notices that file was changed, it automatically "rereads" it. If you have manually changed some data in a crontab file and you don't want to wait while nnCron LITE reloads it automatically, you can hasten the process of crontab reloading by typing in command line:
cron.exe -reload
Syntax that is used in crontab files is very simple: in order to start an application, one only has to specify a desired time of startup in cron format and (after a blank space) the command that should be executed:
<time_in_cron_format> <command>
Comments in crontab files begin with character '#' and continue until the end of line. Crontab file may contain any number of empty lines, which are ignored by the parser. Leading spaces and tab characters are also ignored.
Example:
# application 'chime.exe' is started at 12:15 every week day
15 12 * * 1-5 d:\tools\chime.exe
# the pdf file named in the task is opened daily
# at 12:00 ad at 17:00
0 12,17 * * * e:\my documents\perl\re\re.pdf
# the command file named in the task is executed every 5 minutes
*/5 * * * * d:\fido\bat\blstbbs.cmd
Please note two things:
- when a filename contains blank spaces, there is no need to encase it in quotation
- in order to run command and batch files and open documents, there is no need to call the command interpreter
Of course, that doesn't mean that you cannot enclose filenames with blank spaces between quotation marks or that you cannot call the command interpreter explicitly. Use the way which is more convenient to you:
0 12 * * * "e:\my documents\forth\index.html"
0 8-18 * * 1-5 cmd /c d:\tools\cleanup.bat
The aforementioned syntax is fully compatible with cron syntax, which is widely used in Unix world. In addition to this plain syntax nnCron LITE has several interesting extensions, which let you control how commands will be logged in nnCron LITE log-file and even let you to start full-blown scripts, written in Forth programming language.
Preventing Tasks from Beeing Logged fo a Log File
Let me remind you the plain crontab syntax:
<time_in_cron_format> <command>
If your application starts very often (say, every two minutes), nnCron LITE log-file becomes overcrowded very quickly. If you want to prevent some commands from beeing logged to a log-file, just prepend tilde symbol ('~') before these commands, like this:
<time_in_cron_format> ~<command>
Examples:
# this task will be logged to log-file
0 * * * * c:\test\reminder.bat
# this task will not be logged to log-file
*/2 * * * * ~c:\test\reminder1.bat
Executing Scripts Written in Forth Programming Language
Using another symbol - exclamation point ('!') you can execute any Forth words as a command, which gives you a possibility to write and execute scripts, written in Forth programming Language (SP-Forth).
<time_in_cron_format> !<any Forth words until the end of line>
This is discussed in greater detail in chapter nnCron LITE and Forth Programing Language.
Missed Tasks Handling
Sometimes tasks may have been missed because nnCron LITE was not running at the specified time. Prepend @-symbol before time in cron-format if you want to run missed task 'at the first opportunity' - at the top of the first minute after nnCron LITE startup:
@<time_in_cron_format> <command>
This is discussed in greater detail in chapter Missed Tasks Handling.
Using Environment Variables
nnCron LITE can define local environment variables right in a crontab file. Local environment variables (i. e. variables available only to application started by nnCron) are defined with word SET. See Working with Environment Variables for a more detailed description of the subject.
In command field and in SET constructs you can use the predefined variables of nnCron LITE.
Example:
30 9 * * * %COMSPEC% /c d:\tools\my_bat.bat
0 12 * * 1-5 d:\tools\maintain.bat %DD%-%MMM%-%YYYY%.log
There also exist a special type of syntax allowing to execute any Forth word as a command; this allows to execute scripts of any desired complexity, written in Forth programming language (SP-Forth). This is discussed in greater detail in chapter nnCron LITE and Forth Programing Language.
Cron Format
Cron format is a simple, yet powerful and flexible way to describe time and frequency of various actions. Cron format is extensively used in nnCron LITE.
Traditional (inherited from Unix) cron format consists of five fields separated by blank spaces:
<Minute> <Hour> <Day_of_the_Month> <Month_of_the_Year> <Day_of_the_Week>
nnCron LITE can use both traditional and "enhanced" version of cron format, which has an additional (6th) field: <Year>:
<Minute> <Hour> <Day_of_the_Month> <Month_of_the_Year> <Day_of_the_Week> <Year>
A user can choose the format he would like to use by changing the value of YearField variable in cron.ini. By default, nnCron LITE uses the traditional format, which we are going to use in our examples.
The following graph shows what it consists of:
* * * * *
| | | | |
| | | | +----- Day of the Week (range: 1-7, where 1 is Monday)
| | | +------- Month of the Year (range: 1-12)
| | +--------- Day of the Month (range: 1-31)
| +----------- Hour (range: 0-23)
+------------- Minute (range: 0-59)
Any of these 5 fields may contain an asterisk (*) as their value. An asterisk would mean the entire range of possible values, i.e. each minute, each hour, etc. In the first four fields, nnCron LITE users can also use "nonstandard" character ? (question mark). A description of its functions can be found here.
Any field may contain a list of values separated by commas, (e.g. 1,3,7) or a range of values (two integers separated by a hyphen, e.g. 1-5).
After an asterisk (*) or a range of values, you can use character / to specify that values are repeated with a certain interval between them. For example, you can write "0-23/2" in Hour field to specify that some action should be performed every two hours (it will have the same effect as "0,2,4,6,8,10,12,14,16,18,20,22"); value "*/4" in Minute field means that the action should be performed every 4 minutes, "1-30/3" means the same as "1,4,7,10,13,16,19,22,25,28".
In Month and Day of Week fields, you can use names of months or days of weeks abbreviated to first three letters ("Jan,Feb,...,Dec" or "Mon,Tue,...,Sun") instead of their numeric values.
Examples:
* * * * * Each minute
59 23 31 12 5 One minute before the end of year if the last day
of the year is Friday
59 23 31 Dec Fri Same as above (different notation)
45 17 7 6 * Every year, on June 7th at 17:45
0,15,30,45 0,6,12,18 1,15,31 * 1-5 At 00:00, 00:15, 00:30, 00:45, 06:00, 06:15, 06:30,
06:45, 12:00, 12:15, 12:30, 12:45, 18:00, 18:15,
18:30, 18:45, on 1st, 15th or 31st of each month,
but not on weekends
*/15 */6 1,15,31 * 1-5 Same as above (different notation)
0 12 * * 1-5 (0 12 * * Mon-Fri) At midday on weekdays
* * * 1,3,5,7,9,11 * Each minute in January, March, May, July, September,
and November
1,2,3,5,20-25,30-35,59 23 31 12 * On the last day of year, at 23:01, 23:02, 23:03, 23:05,
23:20, 23:21, 23:22, 23:23, 23:24, 23:25, 23:30,
23:31, 23:32, 23:33, 23:34, 23:35, 23:59
0 9 1-7 * 1 First Monday of each month, at 9 a.m.
0 0 1 * * At midnight, on the first day of each month
* 0-11 * * Each minute before midday
* * * 1,2,3 * Each minute in January, February or March
* * * Jan,Feb,Mar * Same as above (different notation)
0 0 * * * Daily at midnight
0 0 * * 3 Each Wednesday at midnight
nnCron LITE users can use an nonstandard character "?" in the first four fields of cron format. It stands for time of nnCron LITE startup, i. e. when a field is processed, startup time will be substituted for the question mark: minutes for Minute field, hour for Hour field, day of the month for Day of month field and month for Month field.
For example, if you write the following:
? ? * * *
the application will be started on nnCron LITE startup and then will be executed daily at the same time (unless the user doesn't restart nnCron LITE, of course): question marks will be "replaced" by nnCron LITE startup time. For example, if nnCron LITE was started at 8:25, question marks will be substituted in the following way:
25 8 * * *
Some more examples:
# application will be started only on nnCron LITE startup
? ? ? ? *
# application will be started on nnCron LITE startup (e.g. at 10:15)
# and then will be executed again each hour:
# at 11:15, 12:15, 13:15 etc.
? * * * *
# will be executed each minute after nnCron LITE startup until the next hour starts.
# The next day, if nnCron LITE has not been restarted in the meanwhile,
# it will be executed again each minute during the same hour.
* ? * * *
# will be executed daily, every five minutes,
# during the hour when nnCron LITE was started
*/5 ? * * *
Starting and Stopping nnCron LITE
If nnCron LITE is installed under Windows 9*/ME, it starts as a regular application. In Windows NT/2000/XP, nnCron LITE is started by default as a system service.
nnCron LITE home directory contains a batch file named startcron.bat, which checks the version of operating system and automatically start nnCron LITE in an appropriate way: either as a service or as a regular application.
By default, nnCron LITE service is started on system startup using built-in System account, but it can be run "in the name of" any registered user who has sufficient rights (see Note), in other words, nnCron LITE service will use this user account to log in. To do this, select nnCron LITE service in the the Services window (Control panel - Aministrative Tools - Services - cron), open Properties dialogue, select This Account on LogOn tab and enter the user name and password of the required user.
If a user wants to run nnCron LITE as a regular application under Windows NT/2000/XP, he can do this by starting nnCron LITE from command line with key -ns:
cron.exe -ns
In order to stop nnCron LITE and unload it from memory, you can use either of these two methods:
- run batch file stopcron.bat in the program's home directory
- run the following command from command line: cron.exe -stop (if nnCron LITE was started as a regular application rather then as a service)
Note: in order to run nnCron LITE not as System, but as a particular user, this user must have the following rights (see Control Panel - Administrative Tools - Local Security Settings - User Rights Assignment):
- Replace a process level token
- Act as part of the operating system
- Bypass traverse checking
- (user System has these rights by default).
Document history
- Reformat: 2008-05-10.
- First version: 2006-01-09.