A global cron file is provided with the UNIX system. This has been edited to include Talis housekeeping operations such as producing system logs, cleaning up the disk, clearing out error logs and some database related operations.
You can view the contents of the global cron file by logging in as root and typing:
# crontab -l
The cron process executes the jobs it contains at the times that are specified. Each "cron job" is composed of six fields. Fields one to five contain clock information which specify when the command (given in the sixth field) should be executed.
|
Field |
1 |
2 |
3 |
4 |
5 |
6 |
|
Function |
Minute |
Hour |
Day of month |
Month of year |
Day of week |
Command |
|
Ranges |
0-59 |
0-23 |
1-31 |
1-12 |
0-6 |
|
None of the fields can be left blank. For fields 1 through 5 an asterisk must be entered to signify every day or every minute if no specific range or value is required.
An asterisk can be used to signify all values in a field. For example, by placing an asterisk in the third field, the cron daemon will run a job every day. Use asterisks with caution - you may impact on system performance.
Ranges can also be defined by using the minus "-" symbol. For example, if you wanted to run a job for the first four months of the year, you could add 1-4 to the fourth field.
A comma can also be used to select certain values
in the field. If you wanted to run a report every 1st and 15th of the
month, you could add 1, 15 to
the third field.
In the sixth field of each cron line, commands can be added. The Talis convention is to use the /bin/su syntax to run the job as a specified user. For example to run a UNIX script called daliystatus.sc as the user called talis, the following syntax would be appropriate:
/bin/su – talis –c “/users/talis/dailystatus.sc”
Note that the full pathname to the required script is being cited. This
is good practice. You may wish to consider saving such commands in a separate
file where they can be commented and pointed to from the cron line. Jobs
will be much easier to document, test and maintain and will run sequentially.
Reference to an output or report file can be made within the quotes surrounding the command. This will generate output just as if the command had been run directly from the UNIX command prompt. For example, to create a report from the dailystatus.sc script, the output could be re-directed thus:
/bin/su – talis –c “/users/talis/dailystatus.sc >/scratch/dailystatus.out”
Note that the full pathname to the output target is used, in this case re-directing the file into the /scratch directory.
In addition to the output from the script, output can be created that relates to the running of the cron line itself. For example:
/bin/su – talis –c “/users/talis/dailystatus.sc >/scratch/dailystatus.out” 1>/var/tmp/dailystatus.cron 2>/var/tmp/dailystatus.err
The 1> is cron output and the 2> is error information. Typically this is re-directed into the /var/tmp directory. You may also see lines that force any cron error output into the same file as the cron output. This done using the syntax 2>&1 for example:
/bin/su – talis –c “/users/talis/dailystatus.sc >/scratch/dailystatus.out” 1>/var/tmp/dailystatus.cron 2>&1
As quite often the cron output is not required, it can be re-directed into /dev/null. This effectively suppresses the output. For example:
/bin/su – talis –c “/users/talis/dailystatus.sc >/scratch/dailystatus.out” 1>/dev/null 2>&1
If the cron outputs are not directed to a file or to /dev/null then such output will be sent to the UNIX mailbox for the root account. Use re-direction to limit the growth of this mailbox.
The following line would run the dailystatus.sc script as a user called talis, at 8am Monday to Friday. It disregards the date. The script output would be placed into the /scratch directory and the cron output into /var/tmp whilst the cron error output is suppressed.
00 08
*
*
1-5
/bin/su
– talis –c “/users/talis/dailystatus.sc
>/scratch/dailystatus.out” 1>/var/tmp/dailystatus.cronl
2>/dev/null