Table of Contents
Cron
Summary: Cron information and examples.
Date: Around 2013
Refactor: 21 February 2025: Checked links and formatting.
Introduction
Cron is a time-based job scheduler in Unix-like operating systems. Cron enables users to schedule jobs (commands or scripts) to run periodically at fixed times, dates, or intervals. It is commonly used to automate system maintenance or administration tasks, such as backing up databases, updating system files, and monitoring system resources.
Crontab
Crontab is a file that contains the schedule of cron entries to be run at specified times. Each user has their own crontab file, which is stored in the /var/spool/cron directory on most Unix-like systems. The crontab file is a simple text file that contains a list of cron jobs, each on a separate line. Each cron job consists of a line with five fields separated by spaces or tabs, followed by the command to be executed.
Scheduled tasks:
minutes hour dayofmonth month dayofweek user command * * * * * root everyminute */5 * * * * root every5minutes (only works on linux, aix needs 0,5,10,15,20,25,30,35,40,45,50,55) 1 * * * * root everyhour 1 1 * * * root everyday 1 1 * * 0 root everyweek (0=Sunday) 1 1 1 * * root everymonth
In the personal crontab files you need to leave the user out:
* * * * * everyminute
Crontab
To edit a user's crontab enter the command:
crontab -e
To view your crontab file enter the command:
crontab -l
To remove all your crontab jobs enter the command:
crontab -r
Cron Files
Crontabs:
/var/spool/cron
Cron itself:
/var/adm/cron
Cron logfile on solaris:
/var/cron/log
Cron logfile on solaris:
/var/log/cron
Cron Security
CRON users: To allow root only:
- remove /var/adm/cron/cron.deny & /var/adm/cron/cron.allow
To allow anyone to use it:
- touch cron.deny if it does not exist.
To explicitly allow a user and no one else except root:
- touch cron.allow & put user ID in it.
To explicitly deny a user:
- touch cron.deny & put user ID in it.
Note: On Solaris 10 these files are located at /etc/cron.d/
Note: On Red Hat EL 5.5 these files are located at /etc
Cron Editor
Cron uses the editor you want. To make sure it is the one you want use the EDITOR variable:
export EDITOR=vi