Tuesday, November 13, 2012

[OS] Basic Cron Management

Cron is a job scheduler for *nix operating systems. It is time-based, i.e. can periodically run scripts at certain times. Its main purpose is to automate system maintenance.

The crontab file is the configuration file that specifies the commands that will be executed on a specific moment. Users can have their own crontab file or can use the system crontab file.

The base format of the crontab entry is the following:
minute hour day month day-of-week command-to-execute

Basic Commands
1. List all entries in user crontab:
crontab -l

2. Edit the entries in user crontab (it is a vi editor):
crontab -e

The crontab command edits a file (named as the user owner) located on /var/spool/cron (RedHat based operating systems).

Examples
Execute an annual backup on June 15 at 11:45 AM:
45 11 15 06 * /home/potty/annual-backup
Remove all temporary logs everyday at 6:30 PM:
30 18 * * * rm -rf /tmp/log/*