On 2013/08/05 05:01, Les Mikesell wrote:
On Mon, Aug 5, 2013 at 2:00 AM, Gordon Messmer gordon.messmer@gmail.com wrote:
On 08/04/2013 10:17 PM, zGreenfelder wrote:
or... if it really has to be on the first Saturday and only on the first Saturday, then running something like 15 4 1-7 * * /home/app/oracle/backup/monthlybk.sh
with the top of the monthlybk.sh script doing soemthing like
No, really. We went over this. You don't have to modify your scripts. You can put the "test" in the crontab. John's example should work properly:
15 04 * * 6 test $(date +"%d") -le 07 && /home/app/oracle/backup/monthlybk.sh
Cron will run those commands every Saturday. On the first Saturday in the month, "test" will succeed and the script will be run.
On the other hand, putting the test in the script - perhaps with a command line option to override - would also keep it from doing something wrong even if someone happens to run it manually at the wrong time. If I were doing it, I might touch a file when starting and check the timestamp of that to avoid running more than one even on the right day. Sometimes the most clever way isn't really the best.
We do what Les is suggesting. Our script runs the second Saturday of the month (just to be difficult), and is broken into two parts. The part called by cron via "0 9 8-14 * *" does the checking and then calls the real script only if all the conditions are met: it's a Saturday, it's not already running, etc etc. The nice thing about this way is that in the unfortunate case that something went wrong with the cron-fire and we have to manually run the script, we can just do that on the command line without worrying about it not running because out of umpteen tests one failed and killed the execution. And, the initial script is tailored to the machine on which it runs, whereas the main script is the same on all the machines where it runs, so that's handy as well.
Thanks! Miranda