Monday, 20 May 2024

Cron Job on Linux

sudo crontab -u {username} -e

crontab -e

* * * * * /bin/bash /home/phong/backupDB/backup_mysql.sh

crontab -l

- List crontab

Run Cron JobCommand
Every Minute* * * * * /path/to/script
Every 15 Minutes*/15 * * * * /path/to/script
On the 30th Minute of Every Hour30 * * * * /path/to/script
At the Beginning of Every Hour0 * * * * /path/to/script
Every Day at Midnight0 0 * * * /path/to/script
At 2 AM Every Day0 2 * * * /path/to/script
Every 1st of the Month0 0 1 * * /path/to/script
Every 15th of the Month0 0 15 * * /path/to/script
On December 1st - Midnight0 0 1 12 * /path/to/script
Saturdays at Midnight0 0 * * 6 /path/to/script
Every Weekday at 4 AM0 4 * * 1-5 /path/to/script
At 4 AM on Tuesdays and Thursdays0 4 * * 2,4 /path/to/script
Every Other Day at 37 Minutes Past the Hour37 1-23/2 * * * /path/to/script
Every 20 Minutes - Multiple Scripts*/20 * * * * /path/to/script1; /path/to/script2
On Saturdays and Sundays at 12 PM0 12 * * 6,0 /path/to/script
Monday to Friday - Every Hour 9 AM to 5 PM0 9-17 * * 1-5 /path/to/script
Every Hour from 5 PM on Wednesday to 5 AM on Thursday (Job Spans Two Days)0 17-23 * * 3 /path/to/script
0 0-5 * * 4 /path/to/script
Midnight Every Day - Send Output to a Different File0 0 * * * /path/to/script > /path/to/output.log 2>&1

No comments:

Post a Comment

Golang Advanced Interview Q&A