Re: [CentOS] run script on cron job only run on first Saturdat every month???

2013-08-05 Thread Miranda Hawarden-Ogata
On 2013/08/05 05:01, Les Mikesell wrote:
> On Mon, Aug 5, 2013 at 2:00 AM, Gordon Messmer  
> 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 * * 6test $(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


___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


Re: [CentOS] run script on cron job only run on first Saturdat every month???

2013-08-05 Thread Les Mikesell
On Mon, Aug 5, 2013 at 2:00 AM, Gordon Messmer  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 * * 6test $(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.

-- 
   Les Mikesell
 lesmikes...@gmail.com
___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


Re: [CentOS] run script on cron job only run on first Saturdat every month???

2013-08-05 Thread Robert Nichols
On 07/30/2013 04:58 PM, John R Pierce wrote:
> On 7/30/2013 2:32 PM, Keith Keller wrote:
>> 15 04 1-7 * 6 /home/app/oracle/backup/monthlybk.sh
>
> maybe...
>
>   15 04 * * 6 test $(date +"%d") -le 07 && 
> /home/app/oracle/backup/monthlybk.sh
>
> (untested)

Definitely untested!  You need to escape the "%" sign, since it is special
to cron.  Plus, you need to prevent the date command from padding its
output with a leading zero, since that would result in the illegal octal
numbers 08 and 09:

   15 04 * * 6 test $(date +"\%_d") -le 7 && 
/home/app/oracle/backup/monthlybk.sh

-- 
Bob Nichols "NOSPAM" is really part of my email address.
 Do NOT delete it.

___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


Re: [CentOS] run script on cron job only run on first Saturdat every month???

2013-08-05 Thread Gordon Messmer
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 * * 6test $(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.

___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


Re: [CentOS] run script on cron job only run on first Saturdat every month???

2013-08-04 Thread zGreenfelder
On Mon, Aug 5, 2013 at 12:45 AM, Darr247  wrote:

> On 2013-08-04 8:54 PM, Keith Keller wrote:
> > We have already gone over this. The days columns are effectively ORed.
> > So the above job runs every day from the 1st to the 7th, and every
> > Saturday of the month. Read man 5 crontab to see this documented. --keith
>
> Right, but the proposed command doesn't make it much different...
> instead of the 1st through 7th plus every Saturday as it should
> currently be running,
>
> 15 4 1-7 * 7 /home/app/oracle/backup/monthlybk.sh
>
> would make it run the 1st through the 7th and every Sunday... when what
> was requested was running it only the first Saturday of the month.
>
> It seems to me if the asker wants to run it only 1 day per month,
> they're going to have to pick a day and put up with the fact that
> sometimes it's going to happen during weekdays, unless they want to
> twiddle with it every month.
> e.g.
>
> 15 4 1 * * /home/app/oracle/backup/monthlybk.sh
>
> should make it run only on the 1st of the month at 4:15am. (right?)
>
>
>
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
if [`date +%u` -eq 7 ]
then
  echo "saturday!   backup day... writing our drives with y... "
else
   echo nah, wait till saturday.
   exit 0
fi

  rest of your backup stuff.

it's not exactly elegant, but it does seem to get a fix for the original
ask.


-- 
Even the Magic 8 ball has an opinion on email clients: Outlook not so good.
___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


Re: [CentOS] run script on cron job only run on first Saturdat every month???

2013-08-04 Thread Darr247
On 2013-08-04 8:54 PM, Keith Keller wrote:
> We have already gone over this. The days columns are effectively ORed. 
> So the above job runs every day from the 1st to the 7th, and every 
> Saturday of the month. Read man 5 crontab to see this documented. --keith 

Right, but the proposed command doesn't make it much different... 
instead of the 1st through 7th plus every Saturday as it should 
currently be running,

15 4 1-7 * 7 /home/app/oracle/backup/monthlybk.sh

would make it run the 1st through the 7th and every Sunday... when what 
was requested was running it only the first Saturday of the month.

It seems to me if the asker wants to run it only 1 day per month, 
they're going to have to pick a day and put up with the fact that 
sometimes it's going to happen during weekdays, unless they want to 
twiddle with it every month.
e.g.

15 4 1 * * /home/app/oracle/backup/monthlybk.sh

should make it run only on the 1st of the month at 4:15am. (right?)

Anyway, thanks for the reply. :)

___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


Re: [CentOS] run script on cron job only run on first Saturdat every month???

2013-08-04 Thread Keith Keller
On 2013-08-04, Darr247  wrote:
> On 2013-08-04 2:59 PM, Mark LaPierre wrote:
>
> > 15 4 1-7 * 7 /home/app/oracle/backup/monthlybk.sh
>
>
> Can you please point out what's wrong with
>
> 15 04 1-7 * 6 /home/app/oracle/backup/monthlybk.sh
>
> that makes it run every saturday instead of only the first saturday of 
> the month?

We have already gone over this.  The days columns are effectively ORed.
So the above job runs every day from the 1st to the 7th, and every
Saturday of the month.  Read man 5 crontab to see this documented.

--keith


-- 
kkeller-use...@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


___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


Re: [CentOS] run script on cron job only run on first Saturdat every month???

2013-08-04 Thread Darr247
On 2013-08-04 2:59 PM, Mark LaPierre wrote:

 > 15 4 1-7 * 7 /home/app/oracle/backup/monthlybk.sh


Can you please point out what's wrong with

15 04 1-7 * 6 /home/app/oracle/backup/monthlybk.sh

that makes it run every saturday instead of only the first saturday of 
the month?

(Going by the breakout matrix provided in your reply, it looks like your 
solution should make it run the first Sunday of every month.)

Thanks!

___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


Re: [CentOS] run script on cron job only run on first Saturdat every month???

2013-08-04 Thread Mark LaPierre
On 07/30/2013 04:43 PM, mcclnx mcc wrote:
> we have CENTOS 5.5 on DELL server.  One of our script need run on first 
> Saturday every month.
>
>   We have following setup on cron job but it run every Saturday.
>
> 15 04 1-7 * 6 /home/app/oracle/backup/monthlybk.sh
>
>Any one know how to fix it?
>
> Thanks.
> ___
> CentOS mailing list
> CentOS@centos.org
> http://lists.centos.org/mailman/listinfo/centos
>

1 2 3 4 5 /root/backup.sh

* * * * * command to be executed
- - - - -
| | | | |
| | | | - Day of week (0 - 7) (Sunday=0 or 7)
| | | --- Month (1 - 12)
| | - Day of month (1 - 31)
| --- Hour (0 - 23)
- Minute (0 - 59)

15 4 1-7 * 7 /home/app/oracle/backup/monthlybk.sh


-- 
 _
°v°
   /(_)\
^ ^  Mark LaPierre
Registered Linux user No #267004
https://linuxcounter.net/

___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


Re: [CentOS] run script on cron job only run on first Saturdat every month???

2013-07-31 Thread Stephen Harris
On Wed, Jul 31, 2013 at 08:52:02AM -0700, Bart Schaefer wrote:
> As Keith said, it's because the conditions are OR'd.  A careful reading of
> crontab(5) shows that the algorithm is [minute AND hour AND (restricted day
> of week OR restricted day of month) AND month].  Day of week and day of
> month only restrict independently when one or both is "*".

The manpage explicitly says

   Note: The day of a command's execution can be specified by two fields --
   day of month, and day of week.  If  both  fields  are  restricted  (ie,
   aren't  *),  the command will be run when either field matches the cur-
   rent time.  For example,
   "30 4 1,15 * 5" would cause a command to be run at 4:30 am on  the  1st
   and 15th of each month, plus every Friday.


-- 

rgds
Stephen
___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


Re: [CentOS] run script on cron job only run on first Saturdat every month???

2013-07-31 Thread John R Pierce
On 7/31/2013 8:35 AM, m.r...@5-cent.us wrote:
> I agree with the original poster: why doesn't his work, which says 6 in
> the location for day of week, which is Sat.? I'd think it meet the
> criteria "it's somewhere between the 1st and the 7th of the month, and
> it's a Sat", and that I think should be the same as yours

as someone said, the dao of week field is 'or'

-- 
john r pierce  37N 122W
somewhere on the middle of the left coast

___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


Re: [CentOS] run script on cron job only run on first Saturdat every month???

2013-07-31 Thread m . roth
Tony Molloy wrote:
> On Tuesday 30 July 2013 22:58:34 John R Pierce wrote:
>> On 7/30/2013 2:32 PM, Keith Keller wrote:
>> > 15 04 1-7 * 6 /home/app/oracle/backup/monthlybk.sh


Ok, I just mentioned this to my manager, and he told me why: he said he'd
been bitten by this before, and what's happening is that the logic of cron
is odd: it's an OR, *not* and AND, so it's saying "if it's a Sat, *or* if
it's the first seven days of the month

mark

___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


Re: [CentOS] run script on cron job only run on first Saturdat every month???

2013-07-31 Thread Bart Schaefer
On Wed, Jul 31, 2013 at 8:35 AM,  wrote:

>
> I agree with the original poster: why doesn't his work, which says 6 in
> the location for day of week, which is Sat.? I'd think it meet the
> criteria "it's somewhere between the 1st and the 7th of the month, and
> it's a Sat", and that I think should be the same as yours
>

As Keith said, it's because the conditions are OR'd.  A careful reading of
crontab(5) shows that the algorithm is [minute AND hour AND (restricted day
of week OR restricted day of month) AND month].  Day of week and day of
month only restrict independently when one or both is "*".
___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


Re: [CentOS] run script on cron job only run on first Saturdat every month???

2013-07-31 Thread m . roth
Tony Molloy wrote:
> On Tuesday 30 July 2013 22:58:34 John R Pierce wrote:
>> On 7/30/2013 2:32 PM, Keith Keller wrote:
>> > 15 04 1-7 * 6 /home/app/oracle/backup/monthlybk.sh
>>
>> maybe...
>>
>>  15 04 * * 6 test $(date +"%d") -le 07 &&
>>  /home/app/oracle/backup/monthlybk.sh
>>
>> (untested)
>
> Run an incremental backup every day of the month except sundays
>
> 03 03 1-31 * * test `date +\%a` != Sun && /usr/local/bin/backup-rsch-
> inc
>
>
> Run a full backup on the first sunday of the month
>
> 07 03 1-7  * * test `date +\%a` =  Sun && /usr/local/bin/backup-rsch-
> full

I agree with the original poster: why doesn't his work, which says 6 in
the location for day of week, which is Sat.? I'd think it meet the
criteria "it's somewhere between the 1st and the 7th of the month, and
it's a Sat", and that I think should be the same as yours

 makr

___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


Re: [CentOS] run script on cron job only run on first Saturdat every month???

2013-07-31 Thread Tony Molloy
On Tuesday 30 July 2013 22:58:34 John R Pierce wrote:
> On 7/30/2013 2:32 PM, Keith Keller wrote:
> > 15 04 1-7 * 6 /home/app/oracle/backup/monthlybk.sh
> 
> maybe...
> 
>   15 04 * * 6 test $(date +"%d") -le 07 &&
>  /home/app/oracle/backup/monthlybk.sh
> 
> (untested)

Run an incremental backup every day of the month except sundays

03 03 1-31 * * test `date +\%a` != Sun && /usr/local/bin/backup-rsch-
inc


Run a full backup on the first sunday of the month

07 03 1-7  * * test `date +\%a` =  Sun && /usr/local/bin/backup-rsch-
full


Tony



-- 
Linux mufc.tonyshome.ie 2.6.32-358.14.1.el6.x86_64 #1 SMP Tue Jul 16 
23:51:20 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


Re: [CentOS] run script on cron job only run on first Saturdat every month???

2013-07-30 Thread John R Pierce
On 7/30/2013 2:32 PM, Keith Keller wrote:
> 15 04 1-7 * 6 /home/app/oracle/backup/monthlybk.sh

maybe...

15 04 * * 6 test $(date +"%d") -le 07 && 
/home/app/oracle/backup/monthlybk.sh

(untested)

-- 
john r pierce  37N 122W
somewhere on the middle of the left coast

___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


Re: [CentOS] run script on cron job only run on first Saturdat every month???

2013-07-30 Thread Joseph Spenner
>From: mcclnx mcc 

>

>we have CENTOS 5.5 on DELL server.  One of our script need run on first 
>Saturday every month.
>
>We have following setup on cron job but it run every Saturday.  
>
>15 04 1-7 * 6 /home/app/oracle/backup/monthlybk.sh
>
>Any one know how to fix it?

That's pretty clever, and it looks like it should work.
Maybe something is taking priority?
I'd try some experimentation.  Try:

15 04 1-7  6 touch /tmp/foo.test

15 04 1-7  * touch /tmp/foo.test

15 04 1-7 * * touch /tmp/foo.test

15 04 * * 6  touch /tmp/foo.test 

etc.
It might take a while, but you'll find it eventually!

I had a similar problem with Debian, but it turned out to be a weird timezone 
issue confusing me.
___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


Re: [CentOS] run script on cron job only run on first Saturdat every month???

2013-07-30 Thread Keith Keller
On 2013-07-30, m.r...@5-cent.us  wrote:
>> On 7/30/2013 1:43 PM, mcclnx mcc wrote:
>>>
>>> 15 04 1-7 * 6 /home/app/oracle/backup/monthlybk.sh
>
> It certainly doesn't. However, I'm surprised the o/p's crontab entry
> *doesn't* work: it should run only on Sat, and only on when it's somewhere
> between the 1st and the 7th, which could only be the first Sat.

The conditions are ORd, so the job should run every Saturday and every
day from the first to the seventh (which will include a Saturday).  John
is right: most crons do not support "Nth X of the month" where X is a
day of the week.  (I don't know of any.)

--keith

-- 
kkel...@wombat.san-francisco.ca.us


___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


Re: [CentOS] run script on cron job only run on first Saturdat every month???

2013-07-30 Thread m . roth
John R Pierce wrote:
> On 7/30/2013 1:43 PM, mcclnx mcc wrote:
>> we have CENTOS 5.5 on DELL server.  One of our script need run on first
>> Saturday every month.
>>
>>   We have following setup on cron job but it run every Saturday.
>>
>> 15 04 1-7 * 6 /home/app/oracle/backup/monthlybk.sh
>>
>>Any one know how to fix it?
>
> I don't believe cron has any concept of the first day-of-week of each
> month, so you'll need to put some code into your script to exit if its
> NOT the first day-of-week of each month.

It certainly doesn't. However, I'm surprised the o/p's crontab entry
*doesn't* work: it should run only on Sat, and only on when it's somewhere
between the 1st and the 7th, which could only be the first Sat.

 mark

___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


Re: [CentOS] run script on cron job only run on first Saturdat every month???

2013-07-30 Thread John R Pierce
On 7/30/2013 1:43 PM, mcclnx mcc wrote:
> we have CENTOS 5.5 on DELL server.  One of our script need run on first 
> Saturday every month.
>
>   We have following setup on cron job but it run every Saturday.
>
> 15 04 1-7 * 6 /home/app/oracle/backup/monthlybk.sh
>
>Any one know how to fix it?

I don't believe cron has any concept of the first day-of-week of each 
month, so you'll need to put some code into your script to exit if its 
NOT the first day-of-week of each month.



-- 
john r pierce  37N 122W
somewhere on the middle of the left coast

___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos