Technical Tips

Real Time eXecutives, Inc.

Technical Tips


DOS Scheduling on a Weekly/Monthly/Yearly Basis

This document describes a means to allow a batch file to tell if it should be run on a certain date or day, or month. This allows the batch file to be run by the RTX Schedule program on a daily basis, and only perform some type of useful purpose as required (weekly, monthly etc).

In order to perform this type of scheduling, the RTX Schedule.exe program and the RTX Elevel.com program are required, as well as some knowledge of DOS batch programming techniques.


Limitations

The RTX Schedule.exe program has a maximum frequency of 24 hours. It cannot schedule any programs on a less frequent basis. The SCHEDULE.DAT configuration file for the RTX Schedule.exe program, must therefore contain an entry to run a batch file every 24 hours, and this batch file will use the RTX Elevel.com program to check the day or date, in order to decide whether or not it should just exit without doing anything, or if it should run some USEFUL.exe program.


Examples

1) show the day of the week.


The following example shows how the RTX Elevel.com program can be used to check the day of the week.

@echo off
elevel day
if errorlevel 6 goto Saturday
if errorlevel 5 goto Friday
if errorlevel 4 goto Thursday
if errorlevel 3 goto Wednesday
if errorlevel 2 goto Tuesday
if errorlevel 1 goto Monday
goto Sunday
:Monday
echo Today is Monday
goto Exit
:Tuesday
echo Today is Tuesday
goto Exit
:Wednesday
echo Today is Wednesday
goto Exit
:Thursday
echo Today is Thursday
goto Exit
:Friday
echo Today is Friday
goto Exit
:Saturday
echo Today is Saturday
goto Exit
:Sunday
echo Today is Sunday
goto Exit
:Exit

2) show the date/time on the 5th day of each month
The following example shows how the RTX Elevel.com program can be used to check for a particular date in the month.

@echo off
elevel date
if errorlevel 6 goto Exit
if not errorlevel 5 goto Exit
echo. >%temp%\tmp.dat
date <%temp%\tmp.dat >%temp%\tmp1.dat
find "Current" <%temp%\tmp1.dat
del %temp%\tmp.dat
del %temp%\tmp1.dat
:Exit

2) display a "Merry Xmas" message
The following example shows how the RTX Elevel.com program can be used to check for a particular month.

@echo off
elevel month
if errorlevel 13 goto Exit
if not errorlevel 12 goto Exit
elevel date
if errorlevel 26 goto Exit
if not errorlevel 25 goto Exit
echo Merry Xmas everyone
:Exit

Format of the SCHEDULE.DAT file

The ASCII text file SCHEDULE.DAT is the file that the user will create or edit to define the execution times and command lines to be executed by the scheduler program. This file can be created or edited using any ASCII text editor (ie. Brief, PMATE, EDLIN etc.) and can reside either in the current directory or in the DOS path. The schedule table is built from this file on initial execution of the program scheduler or by issuing the "/REBUILD" command (see below).

There are three fields in each record (text line), separated from each other by one or more spaces. The first field is the time of day (since midnight last night) of the first or initial execution of the command line. The second field is the time interval between executions and the third field is the command line to be executed.

The general format is: START_TIME INTERVAL COMMAND_LINE_TO_BE_EXECUTED Times are specified as 1 -to- 3 integers separated by colons, in 24 hour format.

The first integer read will be considered the hours, the second the minutes and the third the seconds. It is not necessary to enter all three integers. For example, if the desired start time is 11 PM, the user can simple enter 23. If the interval time was ten minutes, the user could enter 00:10. If the start time was 1 AM plus 10 seconds the user would have to enter 1:00:10.

The hour field can be greater than 24. For example, if the desired execution interval is every 2 days, the user would enter a 48 for the time interval.

If the execution interval time is zero, the command line will be executed once and only once at the start time specified. If the start time is specified greater than the current time, the command line will be executed once only at that time. If the start time is less than the current time, the command line will be executed once only at the specified start time + 24 hours.

After a "run once only" command has been executed, its entry will be removed from the schedule table. It will not be removed from the SCHEDULE.DAT file. The command line can be re-scheduled by re-executing the schedule program or by re-building the schedule table using the "/REBUILD" command.

If the first character in a schedule definition record is anything other than an ASCII digit (0 -9), the entry will be considered a comment and ignored. This will allow for the inclusion of comments in the schedule definition file. The exception to this rule is the reserved word "NOW". If "NOW" is entered for a start time, the command will be executed at program load (or any time the schedule table is rebuilt). Examples of comment entries and the "NOW" execution, can be seen below in the definition file entry examples.


Elevel.com Options

ELEVEL.com : is a batch process utility program. It is designed to give you greater power from the batch environment, through the use of functions specified in the program command line. Each function returns a value to the batch environment errorlevel parameter.

Command Line Keyword Meaning of Returned Errorlevel
Attribs filespec [mask] Attributes of file [.AND.mask]
Date Date of month from system clock
Day Day of week : 0=Sun, 1=Mon...6=Sat
Diskspace [x:] Number of 16k blocks available
Drive Current Disc drive : A=0,B=1,C=2 ...
Environment Size Size of environment 16
FileDate filespec datespec 0=Same or newer >0=diff
Filefound filespec 0=Found : 1=Not found: 2=0-length
Filesize filespec Length of file in kilobytes
Filetext filespec 'string' 1=Not found : 0=found
Hour Current Hour from system clock
Keyboard 0=buffer empty,1=data to process
Keypress ASCII code of key pressed
Memory Number of 16k blocks available
Minute Current Minute from system clock
Month Current month from system clock

RTX Home Page Back Home
Real Time eXecutives, Inc. 1996 - 2007
Page constructed by
RTX Web Services