All,
I have RE-started my journey into Unixes/Linuxes recently (if 6+ months is that), though I was into it in the earlier years of my college days. I seem to have forgotten things or probably cannot recall certain things at the right time. Nevertheless, here's why I am sending this email.
I did not know about a cron exception and had to assume a particular behaviour. I have detailed that example in Wikipedia, from which, I paste a small section of it.
-----------------------------------------------------------------------------
From Wikipedia:
For "day of the week" (field 5), both 0 and 7 are considered Sunday, though some versions of Unix such as AIX do not list "7" as acceptable in the man page. While normally the job is executed when the time/date specification fields /all/ match the current time and date, there is one exception: if both "day of month" and "day of week" are restricted (not "*"), then either the "day of month" field (3) or the "day of week" field (5) must match the current day.
The above exception would cause trouble when cron is used to specify a task that has to be run on a specific date and time by specifying "day of the month", "month", "day of the week" (where day of the month falls on day of the week). As an example see below
45 19 26 02 06 run_this_task.sh
In an obvious case, one would look at it and read: run_this_task.sh runs on Saturday, 26th Feb at 7:45 PM in the evening
However, CRON looks at it like this:
If it is 26th Feb at 7:45 PM, run_this_task.sh, even though it is NOT Saturday (effectively reading only: 45 19 26 02) OR If it is 7:45 PM on a Saturday, run_this_task.sh, even though it is NOT 26th Feb. (effectively reading only: 45 19 <> <> 06) --------------------------------------------------------------------------
In this case, I would assume, it would not be wise to use CRON to schedule a one time task due to the above "OR" condition. (cron is a 'regular' habit for me ;) )
I think, using "at" is more apt for scheduling one time tasks? (Am I correct?)
-- Roshan Baladhanvi
On Saturday 26 Mar 2011, Roshan wrote:
[snip] In this case, I would assume, it would not be wise to use CRON to schedule a one time task due to the above "OR" condition. (cron is a 'regular' habit for me ;) )
I think, using "at" is more apt for scheduling one time tasks? (Am I correct?)
But if the job were one-time, why add day of the week to the condition? To run moms_birthday.sh at 4pm on July 18, just schedule with:
00 16 18 07 * moms_birthday.sh
If you only want to run it this year, at(1) may be a better alternative; if you want to continue running it every year, use cron.
Regards,
-- Raj