LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-09-2011, 11:59 AM   #1
smilemukul
Member
 
Registered: Jun 2009
Distribution: Redhat,CentOS,Ubuntu,Puppet
Posts: 292

Rep: Reputation: 34
Cron job not scheduling


I have a cron job to schedule the task on the third sunday of the month.I saw the previous threads but didn't find any solution.

How the cron syntax can be written.

Any response will be appreciated.

Thanks
 
Old 01-09-2011, 12:09 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,066
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
man crontab


Cheers,
Tink
 
Old 01-09-2011, 12:23 PM   #3
smilemukul
Member
 
Registered: Jun 2009
Distribution: Redhat,CentOS,Ubuntu,Puppet
Posts: 292

Original Poster
Rep: Reputation: 34
No information is found in man

Thanks
 
Old 01-09-2011, 12:26 PM   #4
repo
LQ 5k Club
 
Registered: May 2001
Location: Belgium
Distribution: Arch
Posts: 8,527

Rep: Reputation: 898Reputation: 898Reputation: 898Reputation: 898Reputation: 898Reputation: 898Reputation: 898
What info do you need?
http://en.wikipedia.org/wiki/Cron
http://adminschoice.com/crontab-quick-reference

Kind regards
 
Old 01-09-2011, 12:29 PM   #5
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,066
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Quote:
Originally Posted by smilemukul View Post
No information is found in man

Thanks
Which distro are you using that it shouldn't provide a man
page for one of the most basic tools out there?!

Just so I can point other new linux users at this thread and
tell them to avoid that distro.



Cheers,
Tink
 
Old 01-09-2011, 12:42 PM   #6
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
The section 5 of the manual provides information about the crontab's syntax:
Code:
man 5 crontab
Anyway it will suggest how to run a cron job every sunday. Then you have to add an extra check for the day of the month, that has to be ≥ 15 and ≤ 21. You can add a conditional expression in the crontab entry itself or at the beginning of the script.

Last edited by colucix; 01-09-2011 at 12:50 PM. Reason: Added extra information
 
Old 01-09-2011, 12:58 PM   #7
networking.dept
Member
 
Registered: Dec 2010
Location: Ahmedabad
Distribution: Red Hat Enterprise Linux and Fedora
Posts: 44

Rep: Reputation: 8
Hello,

Cron format is like below :-

Min Hour DOM MON DOW <script-or-command>

But By googling for some time i have found some interesting

Below scenario taken from :- http://hintsforums.macworld.com/arch...p/t-25110.html

0 4 15-21 * 0 /path/to/my/command

[Just so everybody's clear, the reason for 15-21 is that the third Sunday is always one of those dates, and no other Sunday (2nd, 4th) can ever be those dates. ]

Hope this helps you.
 
Old 01-09-2011, 01:21 PM   #8
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
Quote:
Originally Posted by networking.dept View Post
0 4 15-21 * 0 /path/to/my/command
Nope. This will not work as intended. The two day fields (day of the month and day of the week) in a crontab entry add up: this means the suggested line will run every day between 15th and 21st plus every sunday. The man page (section 5) of crontab clearly states that. This is why I suggested an explicit check for the day of the month in my previous post.

Last edited by colucix; 01-09-2011 at 04:17 PM. Reason: spelling corrected
 
Old 01-11-2011, 01:27 AM   #9
networking.dept
Member
 
Registered: Dec 2010
Location: Ahmedabad
Distribution: Red Hat Enterprise Linux and Fedora
Posts: 44

Rep: Reputation: 8
@colucix, I am explaining cron which i have written and i have taken that cron from some other forum i have already posted Link :-

0 4 15-21 * 0 /path/to/my/command

On Every Minute of 4th Hour on sunday which comes into between 15-21 date every month it will run script.

And as already mentioned there will be only 1 sunday between 15-21 date.

As per my assumption it will work.
 
Old 01-11-2011, 02:00 AM   #10
ashish_neekhra
Member
 
Registered: Nov 2007
Posts: 67

Rep: Reputation: 4
You can check out here ...
 
Old 01-11-2011, 02:04 AM   #11
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
Quote:
Originally Posted by networking.dept View Post
As per my assumption it will work.
Try it and tell me the results on Sunday, 23rd!

Taking a solution from another forum does not necessarily mean it's correct even if they claim it works. Anyway, as clearly stated by the crontab man page:
Quote:
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 current 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.
You can easily try that. Suppose now is 08:00 AM on January, 11st (Tuesday). You can set a cron job like this:
Code:
5 8 15-21 * 2 date >> $HOME/cron.log
and see if it runs. Practice is more helpful than theory!
 
Old 01-12-2011, 04:45 PM   #12
smilemukul
Member
 
Registered: Jun 2009
Distribution: Redhat,CentOS,Ubuntu,Puppet
Posts: 292

Original Poster
Rep: Reputation: 34
Can anyone provide me the syntax for the cronjob which should execute on 3rd sunday.

Thanks
 
Old 01-12-2011, 04:56 PM   #13
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
You could at least show some effort and post what you've tried so far. Have you read the suggested documentation? Have you understood advices in post #6? Have you followed the further discussion? What are your shell scripting skills?
 
Old 01-18-2011, 04:59 PM   #14
smilemukul
Member
 
Registered: Jun 2009
Distribution: Redhat,CentOS,Ubuntu,Puppet
Posts: 292

Original Poster
Rep: Reputation: 34
Can any one tell me what the below expression means while creating a script as,

[`date +%a` = Sun ]

Also need to confirm whether below command is correct for running a cron job for 3rd Sunday as,

0 0 15-21 * * [`date +%a` = Sun ] && /path/to/command

Thanks
 
Old 01-19-2011, 04:41 AM   #15
smilemukul
Member
 
Registered: Jun 2009
Distribution: Redhat,CentOS,Ubuntu,Puppet
Posts: 292

Original Poster
Rep: Reputation: 34
Any response will be appreciated.

Thanks
 
  


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 01:25 PM
adding a perl script to cron.daily / cron.d to setup a cron job CrontabNewBIE Linux - Software 6 01-14-2008 09:16 AM
Scheduling Cron Job chnlinux Linux - Newbie 5 10-16-2007 05:51 AM
LXer: Linux tip: Job scheduling with cron and at LXer Syndicated Linux News 0 07-21-2007 04:16 AM
scheduling monthly job in cron from debian sarge 3.1 sridhar11 Debian 2 10-28-2005 10:03 AM


All times are GMT -5. The time now is 06:52 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration