Using the crontab Command
The crontab command enables the user to view, edit, or remove a crontab file.
Viewing a crontab File
To view the contents of the root crontab file, run the crontab –l command as the root user.
# crontab -l
#ident "@(#)root 1.21 04/03/23 SMI"
# The root crontab should be used to perform accounting data collection.
10 3 * * * /usr/sbin/logadm
15 3 * * 0 /usr/lib/fs/nfs/nfsfind
30 3 * * * [ -x /usr/lib/gss/gsscred_clean ] && /usr/lib/gss/gsscred_clean
As the root user, you can view the contents of any regular user’s crontab file by performing the command:
# crontab -l username
Editing a crontab File
Caution – If you accidentally enter the crontab command on the command line without an option (-l, -e, -r), press the interrupt keys Control-C to exit. Do not press Control-D, this action overwrites the existing crontab file with an empty file.
To create or edit a crontab file, follow these steps:
1. Check that the EDITOR variable is set to the editor you want to use. This instructs the cron utility which editor to use to open the file.
# export EDITOR
2. Run the following crontab command to open your crontab file, and add the appropriate entry.
# crontab -e
30 17 * * 5 /usr/bin/banner "Time to go!" > /dev/console
Note – If the users do not redirect the standard output and standard error of their commands in the crontab file, any generated output or errors are mailed electronically to the user.
Removing a crontab File
The correct way to remove a crontab file is to invoke the command:
# crontab -r username
Typical users can remove only their own crontab file. The root user can delete any user’s crontab file.