what's the cron parameters to run a job every first sunday of each month, to
run at 8am.
--
chito
"James A. Williams" wrote:
> cron can't do this out of the box, you'll have to write a script and let cron
> run the script. cron doesn't know how to tell what is the first Sunday of each
> month.
Nonsense. It can:
0 8 1-7 * 0 /etc/cron.d/first_sunday_of_the_month_08am.sh >/dev/null
2>&1
You'd only need a shell script if you rely on moon phase or such...
Tschuess
Peter
Read the man page for crontab very carefully again.
From the Solaris one:
"Note that the
specification of days may be made by two fields (day of the
month and day of the week). Both are adhered to if speci-
fied as a list of elements. See EXAMPLES."
All of the other fields are ANDed together, but the two day
fields, day-of-week and day-of-month are ORed instead. This
is a pain in the butt, and not obvious without a very close
reading of the man pages, and even closer examination of the
example from the man page.
You need to run on days 1-7 and check for Sunday within the
script.
You should read a bit more of that man page:
| EXAMPLES
[snip]
| 0 0 * * 1
|
| would run a command only on Mondays.
Paul
--
Chris Mattern
"Peter Koch" <ko...@pz.pirmasens.de> wrote in message news:39197D73...@pz.pirmasens.de...
> Hi!
>
> "James A. Williams" wrote:
> > cron can't do this out of the box, you'll have to write a script and let cron
> > run the script. cron doesn't know how to tell what is the first Sunday of each
> > month.
>
> Nonsense. It can:
>
Paul Black wrote:
> Doug Freyburger <dfre...@colltech.com> wrote:
> >
> > Peter Koch wrote:
> > >
> > > > cron can't do this out of the box
> > >
> > > Nonsense. It can:
> > >
> > > 0 8 1-7 * 0 /etc/cron.d/first_sunday_of_the_month ...
> >
> > Read the man page for crontab very carefully again.
> > From the Solaris one:
>
> You should read a bit more of that man page:
> | EXAMPLES
> [snip]
> | 0 0 * * 1
> |
> | would run a command only on Mondays.
>
> Paul
Great, now make it ONLY run on the first Monday of the month. I did it
the opposite. I did what Paul was showing and checked for the day being
between 1 and 7 -- but I did it in the executable part of the crontab
entry.
--
Urban A. Haas
CEO - Urban Technology, Inc.
Minneapolis, MN USA
E-mail: uh...@urbantechnology.com (mailto:uh...@urbantechnology.com)
Phone: (952) 595-8810 Fax: (952) 595-8710
This e-mail was composed of 100% recycled bits.
Peter Koch wrote:
>
> Hi!
>
> "James A. Williams" wrote:
> > cron can't do this out of the box, you'll have to write a script and let cron
> > run the script. cron doesn't know how to tell what is the first Sunday of each
> > month.
>
> Nonsense. It can:
>
> 0 8 1-7 * 0 /etc/cron.d/first_sunday_of_the_month_08am.sh >/dev/null
> 2>&1
>
> You'd only need a shell script if you rely on moon phase or such...
LOL! I love these answers from such 'learned colleagues'.
Pete, what you propose will run on Sunday in addition to the 1st
thru 7th of every month (at 8AM). UNIX systems have these things
called "man pages". You might want to check them out sometime.
Hope this helps,
Don
--
********************** You a bounty hunter?
* Rev. Don McDonald * Man's gotta earn a living.
* Baltimore, MD * Dying ain't much of a living, boy.
********************** "Outlaw Josey Wales"
http://members.home.net/oldno7
like
0 5 <d1> <m1> * <Your procedure>
0 5 <d2> <m2> * <Your procedure>
...
0 5 <d12> <m12> * <Your procedure>
or put only one
0 5 * * 0 <Your procedure>
and make your procedure to touch file /var/somewhere/<month>.month
which will be the indicator, that procedure already has been ran once
and in the very begining of the procedure, make some checkings like.
if exist /var/somewhere/<current month>.month
exit
endif
!here we check for previous month file (we don't want to have trashes on
a disk)
if exist /var/somewhere/*.month file
rm /var/somewhere/*.month
endif
touch /var/somewhere/<current month>.month
Or run it
0 8 * * 0 and start the script with:
if [ `date +%d` -gt 7 ]
then exit
fi
...
Les Mikesell
l...@mcs.com
Errrm, errm, ooops. Must read what the problem is a bit more
carefully next time ...
> This e-mail was composed of 100% recycled bits.
I don't think you should have recylcled mine.
Paul
"Rev. Don Kool" wrote:
> Pete, what you propose will run on Sunday in addition to the 1st
> thru 7th of every month (at 8AM). UNIX systems have these things
> called "man pages". You might want to check them out sometime.
Sure, i do read man pages, but english is not my mother language.
So i simply didn't realize what this meant:
Note that the specification of days may be made by two fields
(day of the month and day of the week). Both are adhered to
if specified as a list of elements. See EXAMPLES.
And i should not skip the examples, cause they are often the best
part of the man pages:
3. As an example of specifying the two types of days:
0 0 1,15 * 1
would run a command on the first and fifteenth of each
month, as well as on every Monday.
> LOL! I love these answers from such 'learned colleagues'.
I can understand why you enjoy my mistake that much. You're a
"real bastard" (TM) and i think you enjoy to hear that too ;-)
Tschuess
Peter
P.S.: Heck, i've learned something today without breaking
anything! Isn't that good news?!?
Peter Koch wrote:
>
> Hi!
>
> "Rev. Don Kool" wrote:
> > Pete, what you propose will run on Sunday in addition to the 1st
> > thru 7th of every month (at 8AM). UNIX systems have these things
> > called "man pages". You might want to check them out sometime.
>
> Sure, i do read man pages, but english is not my mother language.
> So i simply didn't realize what this meant:
>
> Note that the specification of days may be made by two fields
> (day of the month and day of the week). Both are adhered to
> if specified as a list of elements. See EXAMPLES.
>
> And i should not skip the examples, cause they are often the best
> part of the man pages:
>
> 3. As an example of specifying the two types of days:
> 0 0 1,15 * 1
> would run a command on the first and fifteenth of each
> month, as well as on every Monday.
>
> > LOL! I love these answers from such 'learned colleagues'.
>
> I can understand why you enjoy my mistake that much. You're a
> "real bastard" (TM) and i think you enjoy to hear that too ;-)
Being the "BOTF" is a revered USENET tradition.
Marvin wrote:
> James A. Williams wrote:
> > cron can't do this out of the box, you'll have to write a script and let cron
> > run the script. cron doesn't know how to tell what is the first Sunday of each
> > month.
> >
> > "Chito Sto. Domingo" wrote:
> > >
> > > hi guys,
> > >
> > > what's the cron parameters to run a job every first sunday of each month, to
> > > run at 8am.
> > >
> > > --
> > > chito
> Since Number of 1st Sundays/Year is 12, why don't you just put 12
> entries in a crontab ?
That's how users with root do it, not systems administrators.
Marvin <ales.r...@mobitel.si> wrote:
> Since Number of 1st Sundays/Year is 12, why don't you just put 12
> entries in a crontab ?
>
> like
> 0 5 <d1> <m1> * <Your procedure>
> 0 5 <d2> <m2> * <Your procedure>
> ...
> 0 5 <d12> <m12> * <Your procedure>
>
>
> or put only one
> 0 5 * * 0 <Your procedure>
> and make your procedure to touch file /var/somewhere/<month>.month
> which will be the indicator, that procedure already has been ran once
> and in the very begining of the procedure, make some checkings like.
>
> if exist /var/somewhere/<current month>.month
> exit
> endif
> !here we check for previous month file (we don't want to have trashes on
> a disk)
> if exist /var/somewhere/*.month file
> rm /var/somewhere/*.month
> endif
> touch /var/somewhere/<current month>.month
That looks much too complicated and wouldn't work the next year.
If you have such a solution in mind, you could use "at".
Leslie Mikesell wrote:
> Or run it
> 0 8 * * 0 and start the script with:
>
> if [ `date +%d` -gt 7 ]
> then exit
> fi
> ...
That's a cute solution.
A while ago someone had asked me for a solution running a
cron job at the LAST day of the month. Anyone? Don???
Tschuess
Peter
Marry above with something like:
cal | awk '/./ {last = $NF} END {print last}'
(as recently posted in c.u.shell)
Regards,
--
Michael Sternberg | Uni-GH Paderborn
http://www.phys.uni-paderborn.de/~stern/ | FB6 Theoretische Physik
phone: +49-(0)5251-60-2329 fax: -3435 | 33098 Paderborn, Germany
"Who disturrrbs me at this time?" << Zaphod Beeblebrox IV >> <*>
You could run the following script from th 1st to the 7th of every month
at the time you want to execute yr procedure e.g. 8:30 with the
following entry in crontab
30 8 1-7 * * <filename>
and <filename> should look like
if [ `date +%a` = Sun ]
then
<script>
else exit
fi
where script is your procedure you want to run .
I think this should help :-)
In article <391C0482...@pz.pirmasens.de>,
> > if [ `date +%d` -gt 7 ]
> > then exit
> > fi
> > ...
>
> That's a cute solution.
>
> A while ago someone had asked me for a solution running a
> cron job at the LAST day of the month. Anyone? Don???
>
> Tschuess
>
> Peter
>
Sent via Deja.com http://www.deja.com/
Before you buy.
I would simply have a "cron" entry that ran on the 28-31 of each
month. It would call a script that determined if it was indeed the
last day of the current month. It is the same as the original
question of running on the first Sunday of a month. The basic
advise is keep crontab entries simple and have what it calls do the
heavy lifting.
Hope this helps,
Michael Sternberg wrote:
> cal | awk '/./ {last = $NF} END {print last}'
Works great! And it even bears a limple solution for the
"last friday of the month" problem:
cal | awk '($6>0){last=$6} END{print last}'
Tschuess
Peter
"Rev. Don Kool" wrote:
> I would simply have a "cron" entry that ran on the 28-31 of each
> month. It would call a script that determined if it was indeed the
> last day of the current month. It is the same as the original
> question of running on the first Sunday of a month. The basic
> advise is keep crontab entries simple and have what it calls do the
> heavy lifting.
Yes, of course. This, together with the "cal | awk ..." solution of
Michael would solve te "last day of month" problem.
Tschuess
Peter
So cron itself cannot run a job at every first sunday
of the month, it has to be done by a shell script.
Cron will call the script on the desired hour and on
a range of days. The script will exit, if the day
doesn't match.
Crontab entry:
0 8 1-7 * * /etc/cron.d/fsothm0800.sh
fsothm0800.sh looks like:
#!/bin/sh
if [ ! `date +%a` = "Sun" ]; then
exit
fi
:
:
:
A little bit more difficult is to run a cron job on
the last day of the month.
Crontab entry:
0 5 28-31 * * /etc/cron.d/ldothm0500.sh
ldothm0500.sh:
#!/bin/sh
if [ `date +%d` -ne `cal | awk '/./ {last = $NF} END {print last}' ];
then
exit
fi
:
:
:
And finally a cron job that runs on the last friday
of the month:
Crontab entry:
0 3 21-31 * * /etc/cron.d/lfothm0300.sh
lfothm0300.sh:
#!/bin/sh
if [ `date +%d` -ne `cal | awk '($6>0){last=$6} END{print last}' ];
then
exit
fi
:
:
:
Change the two occurences of $6 in the "awk" statement
to something else for other weekdays. You can trim the
output of "cal" to other weeks with "head" and "tail".
Thanks to Leslie Mikesell, Michael Sternberg, Sangeeta
Mishra and Rev. Don Kool.
Peter
\begin{pseudocode}
if tomorrow is 1st of month then
doit
fi
\end{pseudocode}
The simplest way to do this is with GNU date which understands "tomorrow" as
a "date"
BTW - does anyone know how to convert Unix integer seconds into YYYY/MM/DD
using only standard (no GNU or C or perl etc) shell utilities and possibly
AWK? I need to do this and cannot assume that the system it runs on has
anything other than out-the-box solaris ( version < 8).
--
/\ Geoff. Lane. /\ Manchester Computing /\ Manchester /\ M13 9PL /\ England /\
"Bother", said Pooh, as he sunk his twelfth Guinness