Cron is used to schedule tasks to run at specific intervals (minutes, hours, days, months…).
Use SSH to access your server’s command line.
Type:
1 |
crontab -l |
This will show all configured cron jobs on the server.
To add a new cron job or to edit an existing one type:
1 |
crontab -e |
Edit / add as needed. The format for scheduling is (see examples below):
When finished press – “Esc”, “:”, “wq” (w-rite q-uit).
Done!
Cron examples:
Execute every minute –
1 |
* * * * * /scripts/script.sh |
Execute twice daily at 4:00 and 20:00 –
1 |
0 4,20 * * * /scripts/script.sh |
Run on Saturdays at 6:00 –
1 |
0 6 * * sat /scripts/script.sh |
Run every 4 hours –
1 |
0 */4 * * * /scripts/script.sh |
You can comment a cron line with “#”