Note: Cron is great for simple scheduling requests. For complicated scheduling with many dependencies you probably want to go with AirFlow .
Installation
Cron is usually installed by default. It not (e.g., if you are using a Docker image), you can install it using the following command (on Ubuntu).
wajig update && wajig install cron
Alternative to Cron
- 
AirFow is a more rigorous job scheduling system.
 - 
When cron is not available, a simple alternative is to write a simple Python script to run a task at certain times.
 
Tips and Traps
- 
There are 6 fields that you need to fill for a task to be schedule:
m,h,dom,mon,dowandcommand, which stand for the minute, the hour, the day of month, the month, the day of week (of the scheduled time), and the command to run, respectively. The graph below shows possible values for each field.┌────────── minute (0 - 59) │ ┌──────── hour (0 - 23) │ │ ┌────── day of month (1 - 31) │ │ │ ┌──── month (1 - 12) │ │ │ │ ┌── day of week (0 - 6 => Sunday - Saturday, or │ │ │ │ │ 1 - 7 => Monday - Sunday) ↓ ↓ ↓ ↓ ↓ * * * * * command to be executedNotice that abbreviations of days (MON, TUE, etc.) can be used for the field
dow. For exampleSUN,MON,THUfor (day of week) will exectute the command on Sundays, Mondays on Thursdays. Crontab Guru is a quick and simple editor for cron schedule expressions. - 
The information of scheuled tasks are saved in the file
/etc/crontab. It contains scheduled tasks of all users. Though you can schedule tasks by editing the file directly, you'd better not. It is suggested that you use the commandcrontab -eto schedule tasks. If you just want to add crontab tasks, an alternative way is to save the information of tasks in a file (e.g.task.txt), and then run the commandcrontab task.txtto import it. To list all scheduled tasks, run the commandcrontab -l. To remove a sheduled task, use the commandcrontab -r. - 
As long as you use the
crontabcommands to edit the file/etc/crontab, you do NOT have to restartcron.cronwill automatically reload tasks that were changed. The log of cron jobs can be found at/var/log/syslog(Ubuntu) or/var/log/cron(CentOS). If you do not have read permission to cron log files, you'd better redict the output and error messages of a cron job to a log file which you have read access. - 
If your cron job consists of multiple shell commands, it is best to put those commands into a shell script and call the shell script when you schedule your cron job. This has multiple benefits.
- Avoid careless mistakes caused by concatenating multiples commands using 
&&,||or;. - Have better control and logging of each command.
 - Easier to update the job (if you do not have to update the schedule) 
    as you can update the shell script without touching 
crontab. 
 - Avoid careless mistakes caused by concatenating multiples commands using 
 - 
You can schedule a frequently run task using crontab and then reduce the running frequency of the application in your scripts. Below is such an example in Bash shell.
if [[ $(date +%H) =~ ^(10|12|14|16|18)$ ]]; then ... fiThis trick is useful to avoid editing crontab tasks frequently as you can control (or more precisely, reduce) the frequency of the task in your script directly.
 
Cron Job Examples
- 
Run the command
duplicity.lbpat 03:00 every Thursday.0 3 * * 5 duplicity.lbp - 
Run the command
rsnapshot dailydaily at 22:00.0 22 * * * rsnapshot daily - 
Run the command
rsnapshot dailyhourly at the 5th minutes, and redict standard output and error messages to/home/dclong/cron.log.5 * * * * /home/dclong/schedule.sh >> /home/dclong/cron.log 2> &1 - 
Run a command at 22:00 on the 1st day of every month.
0 22 1 * * command_to_run - 
There is no intrinsic way to run commands weekly using cron. One way to approximate that is to run a command multiple times per month. For example, the setup below runs a command at 22:00 on the 1st and 15th day of every month (biweekly approximately) .
0 22 1,15 * * command_to_run 
Start a Crontab Service on Ubuntu
# start cron service
sudo service cron start
# check status of the cron service 
service cron status
# stop the cron service
service cron stop
Check Crontab Logs
You can use the following command to check crontab logs on Ubuntu.
sudo cat /var/log/syslog | grep cron
References
- 
https://stackoverflow.com/questions/18919151/crontab-day-of-the-week-syntax
 - 
https://askubuntu.com/questions/56683/where-is-the-cron-crontab-log