FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > CentOS > CentOS

 
 
LinkBack Thread Tools
 
Old 01-05-2010, 11:05 PM
Markus Falb
 
Default setup schedule cron job every other week?

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 06/01/2010 00:47, mcclnx mcc wrote:
> We have CENTOS 5 on DELL server. I tried to setup schedule cron job to run every other week on Saturday (NOT first and third week ).
>
> Does ayone has ideal how to do it?

Maybe like that...
1 1 * * 6/2 /bla/bin/doit
would read: do /bla/bin/doit at 1:01 every second saturday.
Unverified, but see

#$ man 5 crontab

- --
best regards,
markus
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAktD0+cACgkQYoWFBIJE9eX4yQCfWTgAnKoswA RcqmnbFSWdhLYi
xnwAn033u9HzlD5+uXfxHK+8w47ZF5mM
=lHBG
-----END PGP SIGNATURE-----

_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 01-05-2010, 11:06 PM
Markus Falb
 
Default setup schedule cron job every other week?

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 06/01/2010 00:47, mcclnx mcc wrote:
> We have CENTOS 5 on DELL server. I tried to setup schedule cron job to run every other week on Saturday (NOT first and third week ).
>
> Does ayone has ideal how to do it?

Maybe like that...
1 1 * * 6/2 /bla/bin/doit
would read: do /bla/bin/doit at 1:01 every second saturday.
Unverified, but see

#$ man 5 crontab

- --
best regards,
markus
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAktD1CIACgkQYoWFBIJE9eUP+ACfdrYY/M/kg0P3WMhvJqD6fhnr
V8oAn0qjpppXPyapu6HU4UxIntQu6BYD
=XLyR
-----END PGP SIGNATURE-----

_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 01-05-2010, 11:15 PM
Markus Falb
 
Default setup schedule cron job every other week?

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 06/01/2010 00:47, mcclnx mcc wrote:
> We have CENTOS 5 on DELL server. I tried to setup schedule cron job to run every other week on Saturday (NOT first and third week ).
>
> Does ayone has ideal how to do it?

Maybe like that...
1 1 * * 6/2 /bla/bin/doit
would read: do /bla/bin/doit at 1:01 every second saturday.
Unverified, but see

#$ man 5 crontab

- --
best regards,
markus
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAktD1i4ACgkQYoWFBIJE9eWPhQCdH2hsOBQD4B OlhfbIK4A/0TOL
KgMAoKXMypUhZh7yUB1G/vHhFf09cHNr
=Rr5L
-----END PGP SIGNATURE-----

_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 01-05-2010, 11:18 PM
John R Pierce
 
Default setup schedule cron job every other week?

mcclnx mcc wrote:
> We have CENTOS 5 on DELL server. I tried to setup schedule cron job to run every other week on Saturday (NOT first and third week ).
>

lets see...

date +'%U'

returns the week number of the year, 00-51... and (( expression ))
evaluates arithmetic expressions, returning 'true' if they are non-zero.
weeknumber & 1 will be 0 for even weeks and 1 for odd weeks.

So... set up your cron job to run every Saturday, and in the beginning
of the job script, do something like...

(( $(date +'%V') & 1 )) && exit

which will exit if the week of the year is even. or, in the front of
your crontab line, something like....

30 1 * * 6 (($(date +'%V')&1)) && command-you-want-to-execute-on-even-weeks






_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 01-06-2010, 09:06 AM
John Doe
 
Default setup schedule cron job every other week?

From: mcclnx mcc <mcclnx@yahoo.com.tw>
> We have CENTOS 5 on DELL server. I tried to setup schedule cron job to run
> every other week on Saturday (NOT first and third week ).

Not tested, might work... maybe:
0 0 8-31/14 * 6 /script.sh
8-31/14 should skip the first week and then go every 2 weeks (unless the /14 takes 1 for base instead of the 8)...

JD



_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 01-06-2010, 10:01 AM
John Doe
 
Default setup schedule cron job every other week?

From: John Doe <jdmls@yahoo.com>
> From: mcclnx mcc
> > We have CENTOS 5 on DELL server. I tried to setup schedule cron job to run
> > every other week on Saturday (NOT first and third week ).
> Not tested, might work... maybe:
> 0 0 8-31/14 * 6 /script.sh
> 8-31/14 should skip the first week and then go every 2 weeks (unless the /14
> takes 1 for base instead of the 8)...

Or, just use 2 entries:
0 0 8-14 * 6 /script.sh
0 0 22-28 * 6 /script.sh

JD



_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 01-06-2010, 02:02 PM
"Brent L. Bates"
 
Default setup schedule cron job every other week?

From: mcclnx mcc
> 0 0 8-31/14 * 6 /script.sh

From: John Doe <jdmls@yahoo.com>
> 0 0 8-14 * 6 /script.sh
> 0 0 22-28 * 6 /script.sh

According to the man page, neither of these will not do what the OP
wants. Both will execute the command EVERY Saturday. The first will also
execute it on the 8th and 22nd of the month. The second will execute the
command TWICE a day AND days 8-14 AND 22-28. The man pages says if any of the
day parameters match, the command is executed. Unfortunately for the OP, the
day parameters are an OR operation and not an AND operation.

--

Brent L. Bates (UNIX Sys. Admin.)
M.S. 912 Phone757) 865-1400, x204
NASA Langley Research Center FAX757) 865-8177
Hampton, Virginia 23681-0001
Email: B.L.BATES@larc.nasa.gov http://www.vigyan.com/~blbates/

_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 01-06-2010, 02:49 PM
John Doe
 
Default setup schedule cron job every other week?

From: Brent L. Bates <blbates@vigyan.com>
> From: mcclnx mcc
> > 0 0 8-31/14 * 6 /script.sh
> From: John Doe
> > 0 0 8-14 * 6 /script.sh
> > 0 0 22-28 * 6 /script.sh
> According to the man page, neither of these will not do what the OP
> wants. Both will execute the command EVERY Saturday. The first will also
> execute it on the 8th and 22nd of the month. The second will execute the
> command TWICE a day AND days 8-14 AND 22-28. The man pages says if any of the
> day parameters match, the command is executed. Unfortunately for the OP, the
> day parameters are an OR operation and not an AND operation.

Oops, I missed that part... you are right.
Guess the date check will have to be out of cron...
In case the even/odd week of the year does not work (I am not sure all months will start on odd weeks; do they?), here's another try:
0 0 * * 6 [ $((`date +"%d"`%14)) -ge 8 ] && script.sh
Would that work?

JD



_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 01-06-2010, 07:28 PM
John R Pierce
 
Default setup schedule cron job every other week?

> 0 0 * * 6 [ $((`date +"%d"`%14)) -ge 8 ] && script.sh
> Would that work?
>


0 0 * * 6 [ $((`date +"%V"`&1)) ] && script.sh

would work better. except, uh oh.... what happens at the end/beginning of a year? its quite possible for the even numbered weeks in one year and the even weeks in the next year NOT to be every other week.

this is harder than it looks. I think you'll need to calculate total days since epoch date, modulo 14

[ $(( ($(date +"%s") / 86400) % 14)) -eq 9 ]

where %s is seconds since 1970-01-01 00:00:00 UTC, which was a Wednesday here (PST) at least.

_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 01-08-2010, 03:38 PM
mcclnx mcc
 
Default setup schedule cron job every other week?

Thank you. This script only work on regular enviroment like sh, ksh and bash. When I put on cron job I got error message:

/bin/sh: -c: line 0: unexpected EOF while looking for matching `'

any ideal (CENTOS 4 and 5)?



--- 10/1/5 (二),John R Pierce <pierce@hogranch.com> 寫道:

> 寄件者: John R Pierce <pierce@hogranch.com>
> 主旨: Re: [CentOS] setup schedule cron job every other week?
> 收件者: "CentOS mailing list" <centos@centos.org>
> 日期: 2010年1月5日,二,下午7:18
> mcclnx mcc wrote:
> > We have CENTOS 5 on DELL server.* I tried to
> setup schedule cron job to run every other week on Saturday
> (NOT first and third week ).
> >***
>
> lets see...
>
> date +'%U'
>
> returns the week number of the year, 00-51... and ((
> expression ))
> evaluates arithmetic expressions, returning 'true' if they
> are non-zero.
> weeknumber & 1 will be 0 for even weeks and 1 for odd
> weeks.
>
> So... set up your cron job to run every Saturday, and in
> the beginning
> of the job script, do something like...
>
> (( $(date +'%V') & 1 )) && exit
>
> which will exit if the week of the year is even. or, in the
> front of
> your crontab line, something like....
>
> 30 1 * * 6 (($(date +'%V')&1)) &&
> command-you-want-to-execute-on-even-weeks
>
>
>
>
>
>
> _______________________________________________
> CentOS mailing list
> CentOS@centos.org
> http://lists.centos.org/mailman/listinfo/centos
>

__________________________________________________ _
您的生活即時通 - 溝通、娛樂、生活、工作一次搞定!
http://messenger.yahoo.com.tw/
_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 

Thread Tools




All times are GMT. The time now is 09:04 PM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org