Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Crontab, weekly but ...

32 views
Skip to first unread message

Per Lanvin

unread,
Jan 24, 2013, 8:05:08 AM1/24/13
to

Hi,

I would like a job to be run every week in a month but not the last week.
Does crond support such a request or do I need to write an additional script?

Any hints would greatly appreciated, thank you.


Rgds

/PL

Aragorn

unread,
Jan 24, 2013, 9:44:35 AM1/24/13
to
On Thursday 24 January 2013 14:05, Per Lanvin conveyed the following to
alt.os.linux.redhat...
Considering that a month is always comprised of less than 5 weeks, you
could simply create a separate cron entry for each of the first three
weeks. That seems like the easiest way to do this. ;-)

--
= Aragorn =
(registered GNU/Linux user #223157)

Keith Keller

unread,
Jan 24, 2013, 10:32:59 AM1/24/13
to
On 2013-01-24, Per Lanvin <per.l...@gmail.com> wrote:
>
> I would like a job to be run every week in a month but not the last week.
> Does crond support such a request or do I need to write an additional script?

It depends on how you define "week". If you want your job to run on the
first, second, third, and fourth Fridays of the month, for example, then
Vixie cron does not support this.

However, if you're content with simply having it run four times a month,
a week apart, you can do something like

1 1 7,14,21,28 * * yourJob

--keith

--
kkeller...@wombat.san-francisco.ca.us
(try just my userid to email me)
AOLSFAQ=http://www.therockgarden.ca/aolsfaq.txt
see X- headers for PGP signature information

Bit Twister

unread,
Jan 24, 2013, 11:27:11 AM1/24/13
to
No additional script needed. You can use "date" to retrieve the date
or just about anything you like. Example:

set $(/bin/date '+ %a %u %e %b %H %M %U')
_weekday=$1 # get week day (Mon, Tue,...) %a
_day_in_week=$2 # 1-7 (mon,...sun) %u
_day_in_mo=$3 # 1-31 (day in the month) %e
_mo=$4 # month (Jan, Feb,...) %b
_hr=$5 # hour (0..23) %H
_min=$6 # minute (1...59) %M
_wk=$7 # week number of year with Sunday as first day (00..53) %U

Need last day of month,
set $(cal);shift $(( $# - 1))
_last_day=$1

If you just want to run in the first three weeks, then put something
like this at the top of your cron job/scrip.

if [ $_day_in_mo -gt 22 ] ; then
exit 0
fi

Keith Keller

unread,
Jan 24, 2013, 3:19:44 PM1/24/13
to
On 2013-01-24, Bit Twister <BitTw...@mouse-potato.com> wrote:
>
> No additional script needed. You can use "date" to retrieve the date
> or just about anything you like. Example:

[snip]

> If you just want to run in the first three weeks, then put something
> like this at the top of your cron job/scrip.
>
> if [ $_day_in_mo -gt 22 ] ; then
> exit 0
> fi

If your cron job is not already a script then you would need an
additional script wrapper to do the above. And even if it is a script,
I would still prefer to have a separate script doing the date
calculation. This way, you can run the real script standalone outside
of cron without having to comment out the date calculation or provide a
switch or option for bypassing it. (If you're already supporting
switches then adding a new one is easier than adding it from scratch.)
Or perhaps the cron job is a script but one you prefer not to modify for
other reasons.

Per Lanvin

unread,
Jan 25, 2013, 3:28:49 AM1/25/13
to
All,

Many thanks for valuable input!


Rgds

/PL

Alexander Wiedergold WIEDERGOLD.NET

unread,
Mar 1, 2013, 7:24:54 PM3/1/13
to
cat /etc/power.conf
0 new messages