xBus

Cron

On UNIX machines cron offers scheduling services. The cron daemon is a long-running process that executes commands at specific dates and times. Regularly scheduled commands can be specified according to instructions placed in so-called crontab files.

The xBus provides some batch files, which start the execution of processing one or more interfaces in both directions. The scheduling of these batch files will be configured in a crontab file. The section below explains how to create or edit this file. To determine which batch file should be use for the specific tasks, read Scripts description from the Operation topics.

Here is short description how to run the cron daemon and what it does.

  • cron searches the crontab spool directory for crontab files. These files are named after user accounts. Crontabs found are loaded into memory. Cron wakes up every minute and examines all the stored configuration files, called crontabs, to check each them for commands that may be scheduled to be executed at the current time
  • additionally, cron checks each minute to see if its spool directory's last modified time has been updated. If it has, cron will check the modification time on all crontabs and reload the ones that have been changed. Thus cron need not be restarted whenever a crontab file is modified.
  • a history of all actions taken by cron is recorded in /var/adm/cron/log
  • cron invokes the command from the user's HOME directory with the POSIX shell, (/usr/bin/sh)

Note that different versions of UNIX store cron and support files in different locations and may use a slightly different format. We explain here only the structure that specified for the HP-UX.

/var/adm/cron - main cron directory
/var/spool/cron/atjobs - directory containing at and batch job files
/var/spool/cron/crontabs - directory containing crontab files
/var/adm/cron/log - accounting information
/var/adm/cron/cron.allow - grant access to the cron facility
/var/adm/cron/cron.deny - revoke access to the cron facility
 The crontab File, Format

As it was explained above, the configuration files used to control the operation of cron are called crontab files or cron tables. They are text files which direct the cron daemon's activity. Blank lines and those whose first non-blank character is # will be ignored. The entries in one crontab file are lines of six fields each. The fields are separated by spaces or tabs. The lines have the following format:


minute  hour  monthday  month  weekday  command

The first five are integer patterns that specify when the sixth field (command) should be executed. They have the following ranges of values:

field description value
minute The minute of the hour 0-59
hour The hour of the day 0-23
month day The day of the month 1-31
month The month of the year 1-12
weekday The day of the week 0-6 (0=Sunday)

The first five fields can also use any one of the following formats:

  • an asterisk character (*) to match all values
  • single integer that matches that exact value
  • comma separated list of integers, like 1,3,5 to match one of the listed values
  • a range of integers separated by a dash, like 4-6, to match the values within the range

Note that the specification of days can be made in two fields: month day and weekday. In both are specified in an entry, they are cumulative. For example:

0 0 1,15 * 1 command
- runs command at midnight on the 1st and 15th of each month, as well as every Monday.

To specify days in only one field, set the other field to asterisk (*). For example:

0 0 * * 1 command
- runs command only on Mondays.

The sixth field, command (the balance of a line including blanks in a crontab file), is a string that is executes by the shell at the specified times. Actually it is specifies the absolute path that represents a specific batch file which start the execution of processing one or more interfaces in both directions. For example:

25 2 * * * /opt/integrationlayer/bin/as400filereceiver.ksh WarrantyCreditsIMPHDL
- this entry specifies that the batch as400filereceiver.ksh which start the execution of processing WarrantyCreditsIMPHDL interface will be run at 2:25 on every day of every month.
See this example with one simple crontab file.
 The crontab Command

The crontab files are not generated by editing a the crontab file in the crontab spool directory, instead the command crontab is used to edit, list, create or remove a crontab file for a user.

The crontab command can be used by all the users on a system to create personal crontab as well as by the root account. Users are not allowed to view, edit or create crontab files for other users. Additionally, the use of cron can be denied to users. For more information refer to the crontab manual pages on your system.

You can use the crontab command with the following options:

crontab filename Install filename as your crontab file
crontab -e The edit option copies or creates the current user's crontab file. After editing is complete, the file is installed as the user's crontab file in the crontab spool directory.
crontab -l The list option displays the contents of the current user's crontab file.
crontab -r The remove option empties the contents of the current user's crontab file.