I have a cronjob which runs every 5 minutes all the day in a week. I want to stop this cronjob for 2 hrs only on Sunday. Could you pls help me to set this.
1 Answer
Rather than mess with esoteric crontab schedule entries, have your script check for a file and to not do a full run if the file is present. Then, schedule a second script in cron to create that file on Sunday at the time you want the other script to stop, and then another script 2 hours later in cron to remove the file.
That way, you can be flexible about when the main script does and doesn't run by just changing the times of the create/remove scripts.
-
1In addition to simplicity, this approach also provides a way for you to easily and temporarily "pause" your script if you are doing some other work that might interfere, via a simple command like "touch /etc/myscript/pause", or whatever your "pause file" is called. Then "unpause" with "rm /etc/myscript/pause". Jul 7, 2011 at 17:48