LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices

Reply
 
Search this Thread
Old 08-12-2005, 12:56 PM   #1
rgiggs
Member
 
Registered: Apr 2004
Location: berkeley, ca
Distribution: slk10, winxp
Posts: 313

Rep: Reputation: 30
cron: every 3 weeks on a saturday


hi,
i want a cron job to be run at 00:10AM every 3 weeks on a saturday. in other words, every 3rd saturday. is that possible?

i have tried:

#min hour dom month dow ...
10 0 */21 * 6 ...

is that right? it doesn't seem to work. the most important thing is "on saturday (6), every 3 weeks (*/21)" everything else not important.

no, it's not a problem with absolute path or root privileges.

so, do i have to add this entry to crontab exactly on a saturday for the */21 and 6 to coincide? i was thinking, if i add that entry on, for example, a wednesday, then cron will see, "oh, it's wednesday, so i'm not running it." then exactly 21 days later, cron sees again, "oh, it's a wednesday, so i'm not running it." so the */21 and 6 are never both satisfied, so the job will never run.

in the mean time, i will test the above hypothesis: have to make the */21 and 6 coincide.

thanks.
 
Old 08-12-2005, 01:45 PM   #2
Matir
Moderator
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Ubuntu
Posts: 8,507

Rep: Reputation: 118Reputation: 118
Your command would, I believe, only run it any 21st of the month that falls on a saturday. The */21 field is "day of month", and is not sequential from month to month.

I would just run a script every saturday that decides if it's been 3 weeks. For example:
Code:
#!/bin/bash
BASE="/tmp/every_3_weeks"
if [ -f "${BASE}.1" ]
    then if [ -f "${BASE}.2" ]
        then rm ${BASE}.?
        YOUR_COMMMAND_HERE
    else touch ${BASE}.2
    fi
else touch ${BASE}.1
fi
Not very nice, but it should work for your needs.
 
Old 08-12-2005, 03:13 PM   #3
rgiggs
Member
 
Registered: Apr 2004
Location: berkeley, ca
Distribution: slk10, winxp
Posts: 313

Original Poster
Rep: Reputation: 30
Quote:
Originally posted by Matir
Your command would, I believe, only run it any 21st of the month that falls on a saturday.
hmm, i thought "21" would mean the 21st of a month. i use the "*/" as suggessted by a tutorial somewhere. i tried using "*/2" for min and "*" for other things, then it does indeed run every 2 minutes.

Quote:

I would just run a script every saturday that decides if it's been 3 weeks.
i thought of this, but it will be the last resort

thanks.
 
Old 08-12-2005, 03:18 PM   #4
Matir
Moderator
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Ubuntu
Posts: 8,507

Rep: Reputation: 118Reputation: 118
Yes, well, technically */21 means "Every 21st day of the month", but given that such a range is 1-31 limits things greatly. It *might* try it on the 1st and 22nd, I'm not certain. The point is that its based on the date, not on the last running of the cronjob.
 
Old 08-12-2005, 04:31 PM   #5
rgiggs
Member
 
Registered: Apr 2004
Location: berkeley, ca
Distribution: slk10, winxp
Posts: 313

Original Poster
Rep: Reputation: 30
ic. i look at it again, and "*/3" means: out of all the values returned by *, use the 1st, the 4th, the 7th, ... values.

so, i guess i will just settle with running the cronjob:

at 00:10AM, on the first saturday, of every month.

this is what i come up with.

10 0 1-7 * 6 <user> <command>

the key points, again, are "1-7" and "6": the day of the month is between 1 and 7 inclusive, and the day of the week is saturday.

is that correct?

thanks.
 
Old 08-12-2005, 05:34 PM   #6
Matir
Moderator
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Ubuntu
Posts: 8,507

Rep: Reputation: 118Reputation: 118
That seems reasonable.
 
Old 08-13-2005, 12:17 AM   #7
Berhanie
Senior Member
 
Registered: Dec 2003
Location: phnom penh
Distribution: Fedora
Posts: 1,625

Rep: Reputation: 165Reputation: 165
Quote:
Originally posted by rgiggs
10 0 1-7 * 6 <user> <command>
Unfortunately, that would run at 00:10 on the 1st through the 7th (1-7) of each month, plus every saturday (6).
 
Old 08-13-2005, 01:22 AM   #8
major.tom
Member
 
Registered: Jun 2003
Location: Canada
Distribution: Slackware (current); Gentoo (newbie)
Posts: 142

Rep: Reputation: 15
I have an idea. Theoretically, the 3rd Saturday of the month can only fall between the 15th (if the 1st of the month is a Saturday) to the 21st (if the 1st of the month is a Sunday). So you could just create multiple entries that cover each possibility:

eg.

10 0 */15 * 6 ...
10 0 */16 * 6 ...
10 0 */17 * 6 ...
10 0 */18 * 6 ...
10 0 */19 * 6 ...
10 0 */20 * 6 ...
10 0 */21 * 6 ...

Thoughts?

Garry
 
Old 08-13-2005, 09:27 AM   #9
Matir
Moderator
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Ubuntu
Posts: 8,507

Rep: Reputation: 118Reputation: 118
First off, happy birthday major.tom!

Secondly, the OPs intent was for it to run every 3 weeks, not the 3rd saturday of every month. Your statements would be equivalent to a blanket:
Code:
10 0 15-21 * 6
 
Old 08-13-2005, 02:09 PM   #10
major.tom
Member
 
Registered: Jun 2003
Location: Canada
Distribution: Slackware (current); Gentoo (newbie)
Posts: 142

Rep: Reputation: 15
Thanks, Matir.

I thought Berhanie mentioned that that syntax would execute everyday between the 15th and the 21st PLUS every Saturday.

You rightly point out that the original request was for "every 3rd Saturday". That said, your solution above (on closer inspection) would do the trick.

Cheers!

Garry

Last edited by major.tom; 08-13-2005 at 02:17 PM.
 
Old 08-15-2005, 03:52 PM   #11
rgiggs
Member
 
Registered: Apr 2004
Location: berkeley, ca
Distribution: slk10, winxp
Posts: 313

Original Poster
Rep: Reputation: 30
Quote:
Originally posted by Berhanie
Unfortunately, that would run at 00:10 on the 1st through the 7th (1-7) of each month, plus every saturday (6).
gosh, if that's true, then i find cron very counterintuitive (read sucky ).
my intuition is that the date/time columns are ANDed: (0hour) AND (10min) AND (dom is 1, 2, ..., or 7) AND (dow is saturday) AND (any month).
 
Old 08-15-2005, 03:57 PM   #12
rgiggs
Member
 
Registered: Apr 2004
Location: berkeley, ca
Distribution: slk10, winxp
Posts: 313

Original Poster
Rep: Reputation: 30
Quote:
Originally posted by rgiggs
gosh, if that's true, then i find cron very counterintuitive (read sucky ).
my intuition is that the date/time columns are ANDed: (0hour) AND (10min) AND (dom is 1, 2, ..., or 7) AND (dow is saturday) AND (any month).
yea yea i just read more carefully, and "If both the dom and dow are specified, the command will be executed when either of the events happen." arghh
 
Old 08-15-2005, 05:07 PM   #13
malo_umoran
Member
 
Registered: Dec 2003
Distribution: Desktop: Slackware 13.1 &13.37 | Server: Debian 6.0
Posts: 270

Rep: Reputation: 32
of course, it is possible and your wrote the solution ...

but you have to add it at saturday and without "6":
Code:
10 0 */21 * * *
M.
 
Old 08-15-2005, 05:36 PM   #14
etrumbo
Member
 
Registered: Apr 2005
Location: Michigan, USA
Distribution: Slackware
Posts: 39

Rep: Reputation: 16
Would the */21 method survive a reboot, or a restart of crond?
 
Old 08-15-2005, 06:00 PM   #15
Nille_kungen
Member
 
Registered: Jul 2005
Posts: 213

Rep: Reputation: 43
I think i would use 'at' instead.
It can check and run the command when i start up the computer if it was offline during the specified time.
And also it can mail me errors.
So if it's an importent task i would rather use 'at'
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
shell script using /etc/cron.hourly to execute cron.php file? rioguia Programming 3 06-11-2008 08:09 AM
cron.allow and cron.deny in slackware? tl64 Slackware 5 10-13-2005 09:44 PM
On the lighter side of Saturday morning... JordanH General 5 05-01-2005 12:11 AM
[cron][mdk9.1]cron deamon seems to ignore some task... yannrichet Linux - Newbie 5 06-26-2003 09:57 AM
dual entries in cron log for cron.daily cpharvey Linux - General 3 02-27-2003 02:30 PM


All times are GMT -5. The time now is 03:14 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration