How would I set a cron job to run every 7 minutes between 7pm and 11pm?
Hi,
How would I set a cron job to run every 7 minutes between 7pm and 11pm? Thanks |
Hi and welcome to LinuxQuestions!
Code:
*/7 19-23 * * * /path/to/job.sh |
OK, 7 PM is 19 Hours, 11 PM is 23 Hours.
A quick check of man crontab indicates that Code:
# run every seven minutes between 7 pm and 11 pm Hope this helps some. [EDIT] Or, the "/7" method indicated above -- duh! forgot about that one... [/EDIT] [EDIT] Duh! As colucix points out below, the hours need to be 19-22, not 23. Arrgghh! [/EDIT] |
To run exactly every 7 minutes in the specified interval we can either add the following condition at the beginning of the script:
Code:
#!/bin/bash Code:
* 19-23 * * * [[ $(( ($(date -d "$(date +\%H:\%M)" +\%s) - $(date -d 19:00 +\%s)) \% 420 )) -eq 0 ]] && /path/to/job.sh |
Oops... just realized that in all the suggested crontab entries, the hour interval must be
Code:
19-22 |
All times are GMT -5. The time now is 07:23 AM. |