Museum

Home

Lab Overview

Retrotechnology Articles

⇒ Online Manual

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

cron(8)

mail(1)

binmail(1)

mailx(1)

Mail(1)

sh(1)

crontab(1)  —  Commands

OSF

NAME

crontab − Submits a schedule of commands to cron

SYNOPSIS

crontab [file]

crontab -l | -r | -v

The crontab command copies the specified file, or standard input if you do not specify a file, into the /var/spool/cron/crontabs directory, which contains the crontab files.  The cron command runs commands according to the instructions in the crontab files.  The crontab files are named for users, and the commands in the files are run under the user’s authority.  For example, the commands in the /var/spool/cron/crontabs/root file are run under root authority.  When you use the crontab command, the file under your authority is affected.  For example, if adm invokes the crontab -l command, the /var/spool/cron/crontabs/adm file is affected. 

FLAGS

-lDisplays  the contents of your crontab file. 

-rRemoves the crontab file from the crontab directory. 

-vDisplays the name of your crontab file and the date and time at which you submitted it with crontab. 

DESCRIPTION

After cron runs commands according to the contents of your crontab file, it mails you the output from standard output and standard error for these commands, unless you redirect standard output or standard error. 

NOTE:

When entries are made to a crontab file by using the crontab command, all previous entries in the file are removed. 

You can use the crontab command if your username appears in the /var/adm/cron/cron.allow file.  If that file does not exist, the crontab command checks the /var/adm/cron/cron.deny file to determine if you should be denied access to crontab.  The allow/deny files contain one username per line.  If neither file exists, you can submit a job only if you are operating with superuser authority. 

Each crontab file entry consists of a line with six fields, separated by spaces and tabs, that contain, respectively:

     1.The minute (0 to 59) at which the command sequence executes

     2.The hour (0 to 23) of command execution

     3.The day of the month (1 to 31) of command execution

     4.The month of the year (1 to 12) of command execution

     5.The day of the week (0 to 6 for Sunday to Saturday) of command execution

     6.The shell command to be executed

Each of these fields can contain:

       •A number in the specified range. 

       •Two numbers separated by a dash to indicate an inclusive range. 

       •A list of numbers separated by commas, which selects all numbers in the list. 

       •An asterisk, meaning all legal values. 

Note that the specification of days may be made by two fields (day of the month and day of the week).  If you specify both as a list of elements, both are adhered to.  For example, the following entry:

0 0 1,15 ∗ 1 command

would run command at midnight on the first and fifteenth days of each month, as well as every Monday.  To specify days by only one field, the other field should contain an ∗ (asterisk). 

The cron program runs the command named in the sixth field at the selected date and time.  If you include a % (percent sign) in the sixth field, cron treats everything that precedes it (in that field) as the command invocation, and makes all that follows it available to standard input, unless you escape or double quote the percent sign (\% or %).  An ! (exclamation point) in the sixth field is translated to a newline character. 

Note that the shell runs only the first line of the command field (up to a % or end of line).  All other lines are made available to the command as standard input. 

The cron program invokes a subshell from your $HOME directory.  This means that it will not run your .profile file.  If you schedule a command to run when you are not logged in and you want to have commands in your .profile run, you must explicitly do so in the crontab file.  (For a more detailed discussion of how sh can be invoked, see the sh command.) 

The cron program supplies a default environment for every shell, defining HOME, LOGNAME, SHELL (=/usr/bin/sh), and PATH (=:/usr/bin). 

EXAMPLES

The following examples show valid crontab file entries. 

     1.To write the time to the console every hour on the hour, enter:

0 ∗ ∗ ∗ ∗ echo The hour is ‘date‘. >/dev/console

This example uses command substitution.  For more information, see the sh command. 

     2.To run calendar at 6:30a.m. every Monday, Wednesday, and Friday, enter:

30 6 ∗ ∗ 1,3,5 /usr/bin/calendar -

     3.To define text for the standard input to a command, enter:

0 16 10-31 12 5 /usr/sbin/wall%HAPPY HOLIDAYS!  Drive safely!

This writes a message to all users logged in at 4:00p.m. each Friday between December 10 and 31. The text following the % (percent sign) defines the standard input to the wall command as follows:

HAPPY HOLIDAYS!  Drive safely!.

NOTES

     1.If your user ID is associated with more than one username, crontab uses the first username that appears in the /etc/passwd file, regardless of which username you might actually be using. 

     2.If cron.allow exists, the superuser’s username must appear there for that superuser to be able to use the command. 

FILES

/var/spool/cron/crontabsDirectory containing the crontab files. 

/var/adm/cron/cron.allowList of allowed users. 

/var/adm/cron/cron.denyList of denied users. 

/etc/passwdContains user information. 

$HOME/.profileUser profile. 

RELATED INFORMATION

Commands:  cron(8), mail(1), binmail(1), mailx(1), Mail(1), sh(1). 

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026