Crontab

Crontab

export EDITOR=vi to specify a editor to open crontab file.

crontab -e Edit your crontab file, or create one if it doesn't already exist.

crontab -l Display your crontab file.

crontab -r Remove your crontab file.

crontab -v Display the last time you edited your crontab file. (This option is only available on a few systems.)

A crontab file has five fields for specifying day , date and time followed by the command to be run at that interval.

* * * * * command to be executed

| | | | | +----- day of week (0 - 6) (Sunday=0)

| | | | +------- month (1 - 12)

| | | +--------- day of month (1 - 31)

| | +----------- hour (0 - 23)

| +------------- min (0 - 59)

1,5 would be 1 or 5 1-5 would be 1 to 5

An example crontab:

SHELL=/bin/bash

PATH=/sbin:/bin:/usr/sbin:/usr/bin

MAILTO=root

HOME=/

# run-parts

01 * * * * root run-parts /etc/cron.hourly

02 4 * * * root run-parts /etc/cron.daily

22 4 * * 0 root run-parts /etc/cron.weekly

42 4 1 * * root run-parts /etc/cron.monthly

Some arbitrary usage examples

# Backup

0 22 * * 1-5 root /root/scripts/backup.sh > /dev/null 2&>1

# Offsite backup

0 22 * * 1-5 root /root/scripts/backup.rsnap daily > /dev/null 2&>1

# Kept script - check raid

0 8,12 * * * root /root/scripts/check-raid

# Kept script - Check free space

# 36 5 * * * root /root/scripts/check-space > /dev/null 2&>1

# Update time

37 5 * * 1 root /root/scripts/update-time > /dev/null 2&>1

# Update McAfee Anti-Virus definitions

# 0 6 * * * root /root/scripts/update-uvscan > /dev/null 2&>1

# Update Clam Anti-Virus definitions

# 0 6 * * * root /root/scripts/update-clamav > /dev/null 2&>1

# Download email

# */15 * * * * root /root/scripts/getmail > /dev/null 2&>1

# Virus Scan UV

# 05 22 * * 6 root /root/scripts/virus-scan-uv > /dev/null 2&>1

0 2 * * 0 root > /root/scripts/clamscan > /dev/null 2&>1

# Offsite backup

11 22 * * 5 root /root/scripts/offsite > /dev/null 2&>1