crontab

SysAdmin: crontab - maintains crontab files for individual users

Cron

Cron is a *nix/Linux scheduled task system which has various ways to configure, all of which, can live happily together.

crontab

Personal cron entries are accessed by issuing the crontab command and have no “user” field, as they are per-user crontabs.

# crontab for <user>
#
SHELL=/bin/zsh
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/home/<user>/bin
MAILTO=<user>
HOME=/home/<user>
#
# .---------------- minute (0-59)
# | .-------------- hour (0-23) 
# | | .------------ day of month (1 - 31)  
# | | | .---------- month (1 - 12) OR jan,feb,mar,apr ...   
# | | | | .-------- day of week (0 - 6) (Sunday=0 or 7)  OR sun,mon,tue,wed,thu,fri,sat    
# | | | | |
# * * * * * /full/path/and/command_to_be_executed
#
## Awesome examples
#
## Run something and redirect its output to the bin
* * * * * pwd 2>&1 >/dev/null
#
## Run something and log errors to a file
* * * * * pwd 2>&1 >>/var/log/somefile
#
## This one shows a periodic backup which runs quietly (normally), but any errors will be redirected to syslog (AWESOME)!
## Backup /home to the NAS, daily.
00 00,12 * * * /usr/bin/rsync -aSH --delete /home [[email protected]](/cdn-cgi/l/email-protection):/Backups/Pi/ 2>&1 | /usr/bin/logger -p cron.warning -t Backup_Pi-2-NAS

/etc/crontab and /etc/cron.d/*.cron

Cron treats the files in /etc/cron.d as extensions to the /etc/crontab file (they follow the special format of that file, i.e. they include the user field). The intended purpose of this feature is to allow packages that require finer control of their scheduling than the /etc/cron.{daily,weekly,monthly} directories allow to add a crontab file to /etc/cron.d.

This is used for has a “user” field…

# .---------------- minute (0 - 59)
# | .-------------- hour (0 - 23) 
# | | .------------ day of month (1 - 31)  
# | | | .---------- month (1 - 12) OR jan,feb,mar,apr ...   
# | | | | .-------- day of week (0 - 6) (Sunday=0 or 7)  OR sun,mon,tue,wed,thu,fri,sat    
# | | | | | .------ username to run as (it's not a personal crontab)
# | | | | | |
# * * * * * <user> /full/path/and/command_to_be_executed