Using crontab some times can get little confusing due to the field names, values, syntax, redirection. Learn crontab with different examples for each fields, you can use with minor modifications or create new ones based off these examples
Crontab Examples :
The fields used by crontab and their meaning.
Crontab Examples :
All the examples uses date command to show the command execution time but it can be substituted by any other command or program or script.
1. Every 15 minute – every hour, every day
15,30,45,00 * * * * date >> /tmp/every15minutes
2. Once in a hour at 10th minute, every hour, every day
10 * * * * date >> /tmp/everyHRat10minutes
3. at 25th minute, after 4 hrs , at 10 AM, 2pm 6pm, 10 pm , every day
25 10,14,18,22 * * * date >> /tmp/everyHRat10inutes
4. Once in a day at 11.30 PM
30 23 * * * date >> /tmp/everyHRat10inutes
at 30 minutes past mid night
30 00 * * * date >> /tmp/everyHRat10inutes
5. At 5 day intervals at 10.10 AM every month
10 10 5,10,15,20,25,30 * *
Every 2nd day of every month at 10.20 AM every month
10 10 2 * * date >> /tmp/everyHRat10inutes
6. on 5th day every quarter, 3 month interval , at 11.30 AM
30 11 5 3,6,9,12 * date >> /tmp/everyHRat10inutes
on 5th day on Jan and Feb only, at 11.30 AM
30 11 5 1,2 * date >> /tmp/everyHRat10inutes
once in a year on Jan 2nd at 11.30 AM
30 11 2 1 * date >> /tmp/everyHRat10inutes
7. Every Monday at 10.15 AM
15 10 * * 1
every Monday & Friday at 10.15 AM
15 10 * * 1,5 date >> /tmp/everyHRat10inutes
Every weekday, except Saturday & Sunday
15 10 * * 1,2,3,4,5 date >> /tmp/everyHRat10inutes
8. disable email by redirecting output to /dev/null
10 * * * * date >> /tmp/everyHRat10minutes >/dev/null 2>&1
9. capture std out and std errors in a output file
10 * * * * date >> /tmp/everyHRat10minutes > /tmp/outfile.log 2>&1
10 Source env for the programs
14 * * * * source /home/app/.bashrc; .date
Further Reading :
https://www.adminschoice.com/crontab-quick-reference
https://www.adminschoice.com/what-does-21-mean-in-shell