Schedule Tasks with Crontab
The crontab is used for running specific tasks on a regular interval on Linux and macOS operational systems. Crontab is similar to Windoze's Task Scheduler. Crontab is very useful for routine tasks like scheduling system scanning, daily backups etc.
Crontab executes jobs automatically in the backend on a specified time and interval. You can also use crontab to run tasks only once.
<Minute> <hour> <Day_of_the_Month> <Month_of_the_Year> <Day_of_the_Week> <Command>

You can use this easy to use cron editor hosted at https:/crontab.guru.
Crontab executes jobs automatically in the backend on a specified time and interval. You can also use crontab to run tasks only once.
Export the Default Editor
First things first, if you haven't done by now set the default editor for Terminal. Most people use vi but for the first time user nano is easier. Set the default editor like this:export EDITOR='nano'If you want to retain this configuration when you close the Terminal then add this line to your .bashrc, .profile, .bash_profile or whatever initialization script your shell uses.Linux Crontab Syntax
Linux crontab has six fields. 1-5 fields defines the date and time of execution. The 6th field is used for command or script to be executed. The crontab syntax are as following:
Value Operators
* any value
, value list separator (1,2,3,6,9)
- range of values (2-9)
/ step values (*/10 that is every 10... minutes, hours etc)
, value list separator (1,2,3,6,9)
- range of values (2-9)
/ step values (*/10 that is every 10... minutes, hours etc)
Add/Edit Crontab
To add or update job in crontab, use below command. It will open crontab file in the editor where a job can be added/updated.crontab -eBy default, it will edit crontab entries of current logged in user. To edit other user crontab use this command:crontab -u username -eSaving Crontab
When you finish editing your cron script save it and exit the editor, after that the rules will be in effect. The way to do that with nano is to pressCTRL+O to save and CTRL+X to exit.List Crontab
To list your user's crontab list type:crontab -lExamples
Execute Twice a Day, at 4AM and 1PM:
0 4,13 * * * /path/script.shExecute on Every Minute:
* * * * * /path/script.shExecute Every 10 minutes:
*/10 * * * * /path/monitor.shExecute on Selected Months:
* * * jan,may,aug * /path/script.shExecute at 2 PM on Selected Days:
0 14 * * sun,fri /path/script.shExecute on the First Sunday of Every Month at 2AM:
0 2 * * sun [ $(date +%d) -le 07 ] && /path/script.shExecute Every Four Hours:
0 */4 * * * /path/script.shExecute Twice Every Sunday and Twice Every Monday at 4AM and 2PM:
0 4,14 * * sun,mon /path/script.shExecute Every 30 Seconds:
* * * * * /path/script.sh
* * * * * sleep 30; /path/script.sh
Multiple Tasks in Single Cron:
* * * * * /path/script.sh; /path/script2.shUsing Simple Timestamps:
@yearly /path/script.sh@monthly /path/script.sh@weekly /path/script.sh@daily /path/script.sh@hourly /path/script.shAnd @reboot to run on the system startup:@reboot /path/script.shBackup Current Cron List:
crontab -l > cron_backup.txtRestore Cron List from Backup:
crontab cron_backup.txtRemove All Cron Jobs:
crontab -rYou can use this easy to use cron editor hosted at https:/crontab.guru.