LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 06-02-2014, 01:24 AM   #1
Iyyappan
Member
 
Registered: Dec 2008
Location: Chennai, India
Distribution: CentOS 5, SLES 11
Posts: 245

Rep: Reputation: 4
cron job to run on 2-27 every month excluding Sundays


Hi,

can some one guide how to schedule a cron to run between 2nd to 27th of every month except Sundays
 
Old 06-02-2014, 01:39 AM   #2
Iyyappan
Member
 
Registered: Dec 2008
Location: Chennai, India
Distribution: CentOS 5, SLES 11
Posts: 245

Original Poster
Rep: Reputation: 4
For week days

00 08 2-27 * 1-5 /usr/local/script.sh is this correct.... I do not have a test server to test it..


For week end

00 08 2-27 * 0 /usr/loca/script.sh

the above one is running all days between 2 - 27 and also running on sunday..

I want the script to run on every sunday only between 2 - 27..

Last edited by Iyyappan; 06-02-2014 at 01:49 AM.
 
Old 06-02-2014, 04:09 AM   #3
eklavya
Member
 
Registered: Mar 2013
Posts: 633

Rep: Reputation: 141Reputation: 141
Try this
Quote:
00 08 2-27 * 1-6 * /usr/local/script.sh
It will run each month between date 2 & 27 except sundays.
 
1 members found this post helpful.
Old 06-02-2014, 04:15 AM   #4
Iyyappan
Member
 
Registered: Dec 2008
Location: Chennai, India
Distribution: CentOS 5, SLES 11
Posts: 245

Original Poster
Rep: Reputation: 4
Quote:
Originally Posted by eklavya View Post
00 08 2-27 * 1-6 * /usr/local/script.sh .

what does the last * mean
 
Old 06-02-2014, 06:48 AM   #5
eklavya
Member
 
Registered: Mar 2013
Posts: 633

Rep: Reputation: 141Reputation: 141
Every year.
 
Old 06-02-2014, 07:32 AM   #6
Iyyappan
Member
 
Registered: Dec 2008
Location: Chennai, India
Distribution: CentOS 5, SLES 11
Posts: 245

Original Poster
Rep: Reputation: 4
For week end can u help me

00 08 2-27 * 0 /usr/loca/script.sh

the above one is running all days between 2 - 27 and also running on sunday..

I want the script to run on every sunday only between 2 - 27..
 
Old 06-02-2014, 07:59 AM   #7
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
http://www.openjs.com/scripts/jslibr...os/crontab.php
suggests:
Code:
*	8	2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27	*	1,2,3,4,5,6
but that, I believe can be shortened to
Code:
* 8 2-27 * 1-6
and another crontab site shows:
Code:
* 8 2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27 * 1,2,3,4,5,6 /path/to/script
But what if say, the 13th is a Sunday?

This raises the question, does every first day of the week occur on Sunday everywhere when view by "cal" output?
or is Sunday always "0" on all systems? Isn't this based on LOCALE?

and perhaps another example of forcing cron to do our will:
https://www.linuxquestions.org/quest...9/#post5178849

I am intrigued and confused.

Sorry, if that's not much help.
 
Old 06-02-2014, 09:20 AM   #8
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: CentOS
Posts: 4,535

Rep: Reputation: 2077Reputation: 2077Reputation: 2077Reputation: 2077Reputation: 2077Reputation: 2077Reputation: 2077Reputation: 2077Reputation: 2077Reputation: 2077Reputation: 2077
cron cannot directly do what you are asking. When you specify something other than "*" for both day-of-month and day-of-week, the logical operation is to run the command when either one is satisfied. To exclude days or dates, your command string needs to include a test using the date command.

In a crontab, either 0 or 7 is Sunday. If you like your weeks to begin on Sunday, use 0-6. If your week begins on Monday, use 1-7.
 
Old 06-03-2014, 03:05 AM   #9
Iyyappan
Member
 
Registered: Dec 2008
Location: Chennai, India
Distribution: CentOS 5, SLES 11
Posts: 245

Original Poster
Rep: Reputation: 4
Quote:
Originally Posted by rknichols View Post
To exclude days or dates, your command string needs to include a test using the date


ok then I need to write a script to check for sunday alone and execute it .. and also check that date is between 2 - 27
 
Old 06-03-2014, 08:47 AM   #10
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: CentOS
Posts: 4,535

Rep: Reputation: 2077Reputation: 2077Reputation: 2077Reputation: 2077Reputation: 2077Reputation: 2077Reputation: 2077Reputation: 2077Reputation: 2077Reputation: 2077Reputation: 2077
You can do it right in the crontab line, as shown in the link that Habitual posted.
Code:
00 08 2-27 * * test $(date +\%w) -ne 0 && /usr/local/script.sh
Note that the "%" character is special in a crontab and needs to be escaped with a backslash.
 
1 members found this post helpful.
Old 06-03-2014, 09:56 AM   #11
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
good stuff rk!
 
Old 06-03-2014, 10:42 AM   #12
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 23,657

Rep: Reputation: 6911Reputation: 6911Reputation: 6911Reputation: 6911Reputation: 6911Reputation: 6911Reputation: 6911Reputation: 6911Reputation: 6911Reputation: 6911Reputation: 6911
Quote:
Originally Posted by Iyyappan View Post
Hi,
can some one guide how to schedule a cron to run between 2nd to 27th of every month except Sundays
There are different ways to do it, but there have been many, MANY threads on LQ about cron scheduling, and many more on Google with fairly complex answers. If you looked on LQ:
http://www.linuxquestions.org/questi...2/#post4654486

...you'd have found at least one example, with a fairly good explanation. Apply what's in there.
 
1 members found this post helpful.
Old 06-04-2014, 04:20 AM   #13
Iyyappan
Member
 
Registered: Dec 2008
Location: Chennai, India
Distribution: CentOS 5, SLES 11
Posts: 245

Original Poster
Rep: Reputation: 4
thanks a lot ...
 
  


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
[SOLVED] Scheduling a CRON job to run on the first Sunday of the month New2Linux2 Linux - Software 10 11-08-2016 12:25 PM
[SOLVED] cron job to run 1st Tue of month and at random time between 3am and 4am keif Programming 6 05-29-2014 03:58 PM
[SOLVED] Run a Cron Job on Last Thursday of Every Month devUnix Linux - General 6 11-01-2013 09:09 AM
end of month cron job tekmann33 Linux - Newbie 5 12-12-2009 06:40 AM
Cron Job to run on 2nd and 4th Friday of each month rust8y Linux - General 1 06-25-2007 09:07 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

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

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration