System Administration Guide

How to Create or Edit a crontab File

  1. Be sure that you have access to the editor of your choice.

  2. (Optional) To create or edit a crontab file belonging to root or another user, become superuser.

  3. Create a new crontab file, or edit an existing one.


    $ crontab -e [username]

    username

    Name of another user's account, and requires root privileges to create or edit. 


    Caution - Caution -

    If you accidentally enter the crontab command with no option, press the interrupt character for your editor. This allows you to quit without saving changes. Exiting the file and saving changes at this point would overwrite an existing crontab file with an empty file.


  4. Add command lines to the file, following the syntax described in "Syntax of crontab File Entries".

  5. Exit the file, saving the changes.

    The crontab file will be placed in /usr/spool/cron/crontabs.

  6. Verify the crontab file by using the crontab -l command.


    # crontab -l [username]

Example--Creating or Editing a crontab File

The following example shows how to create a crontab file for another user.


# crontab -e jones

The following command entry added to a new crontab file will automatically remove any log files from the user's home directory at 1 every Sunday morning. Because the command entry does not redirect output, redirect characters are added to the command line after *.log to make sure that the command executes properly.


# This command helps clean up user accounts.
1 0 * * 0 rm /home/jones/*.log > /dev/null 2>&1