The purpose of this guide is to show you how to setup crontab task.
You can edit crontab by entering the following terminal command for current user:
Entering the above command will open a terminal editor with crontab file.
A crontab file has six fields for specifying minute, hour, day of month, month, day of week and the command to be run at that interval. Seebelow:
* * * * * 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)
* * * * * <command> #Runs every minute 30 * * * * <command> #Runs at 30 minutes past the hour 45 6 * * * <command> #Runs at 6:45 am every day 00 1 * * 0 <command> #Runs at 1:00 am every Sunday 00 1 * * 7 <command> #Runs at 1:00 am every Sunday 30 8 1 * * <command> #Runs at 8:30 am on the first day of every month
By default a cron job will send an email to the user account executing the cronjob. If this is not needed put the following command at the end of the cron job line:
$sudo crontab -u <username> -e
If you want to regularly run a command requiring administrative permissions, edit the root crontab file:
$sudo crontab -e
The cron will look at “MAILTO” if it has any reason to send mail as a result of running commands in “this” crontab. If MAILTO is defined (and non-empty), mail is sent to the user so named. First open your crontab file:
To send email to firstname.lastname@example.org, enter:
If MAILTO is defined but empty (MAILTO=””), no mail will be sent.
Otherwise mail is sent to the owner of the crontab.