Gary Antonellis
asked on
CRON statement to run every 3 minutes except on Monday morning 12am to 2am
We need to run a service every 3 minutes except while Payroll is being processed which is Monday morning 12am to 2AM
Instead of messing with a very complicated cron, you can do this:
First condition checks to see if it's Monday (1), next condition checks to see if it's between hour 00 or 01 (literally 12AM to 1:59AM), and does nothing but echos "do nothing"
Place the actual script / job cron is running every 3 min where you see "echo my command to execute goes here".
Then, you can use a very simple every 3 min in your cron.
if [ $(date +%u) = 1 ]
then
if [ $(date +%H) = 00 -o 01 ]
then
echo do nothing
fi
else
echo my command to execute goes here
exit
fi
First condition checks to see if it's Monday (1), next condition checks to see if it's between hour 00 or 01 (literally 12AM to 1:59AM), and does nothing but echos "do nothing"
Place the actual script / job cron is running every 3 min where you see "echo my command to execute goes here".
Then, you can use a very simple every 3 min in your cron.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
@omarfarid,
you could turn your really fine solution into a perfect one by replacing "0,1" with "2-23", don't you think so?
The author requires the task not to run between 0:00 and 1:59!
you could turn your really fine solution into a perfect one by replacing "0,1" with "2-23", don't you think so?
The author requires the task not to run between 0:00 and 1:59!
Thank you for the correction :)
ASKER
I am getting a error that both expressions are invalid in CRONMAKER.com. I am also getting an error when I try saving the Cron string in our application, which uses Java quartz. Is this a Cron syntax not supported by Java?
Thanks!
Thanks!
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Open in new window
Please note that in crontab the percent signs must be escaped with a backslash ("\%")In the system crontab add the required username as the sixth field ("*/3 * * * * username [[ ... ...")