Linux - Server This forum is for the discussion of Linux Software used in a server related context. |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
04-18-2011, 06:52 AM
|
#1
|
Member
Registered: Mar 2010
Location: INDIA (chennai)
Distribution: centos
Posts: 271
Rep:
|
Confused with cron
Hi all,
I have a cron job like this.
04 07 17 04 02 sh -x myscript
this means the file myscript should be executed when the server date comes to Apr 17 on Tuesday at 07 04 am.
But the file myscript runs on every tuesday of April month. Whats wrong with cron i am very confused. Your suggestions please.
Thanks®ards,
Dinesh.
|
|
|
04-18-2011, 07:07 AM
|
#2
|
Member
Registered: Mar 2009
Distribution: CentOS - Ubuntu - Debian
Posts: 83
Rep:
|
Hi,
Try reading the man page for the cron file format
man 5 crontab
The format is:
minute 0-59
hour 0-23
day of month 1-31
month 1-12 (or names, see below)
day of week 0-7 (0 or 7 is Sun, or use names)
Best regards,
|
|
|
04-18-2011, 07:14 AM
|
#3
|
Member
Registered: Mar 2010
Location: INDIA (chennai)
Distribution: centos
Posts: 271
Original Poster
Rep:
|
hi,
Thanks i did that, But no improvement in my problem.
|
|
|
04-18-2011, 07:49 AM
|
#4
|
Moderator
Registered: Aug 2002
Posts: 26,366
|
FYI
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, are
not *), 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.
|
|
|
1 members found this post helpful.
|
04-18-2011, 09:58 AM
|
#5
|
Member
Registered: Mar 2010
Location: INDIA (chennai)
Distribution: centos
Posts: 271
Original Poster
Rep:
|
Hi michaelk,
Thanks for your reply.
``30 4 1,15 * 5'' from your example.
The command should run only when the date 1st and 15th of the month comes on friday. Is that possible.
|
|
|
04-18-2011, 10:27 AM
|
#6
|
Moderator
Registered: Aug 2002
Posts: 26,366
|
FYI that was a quote from the man pages...
If you want to run a job on a particular day / day of the week then you need something like the following.
04 07 1,15 * * [ "$(date '+\%a')" == "Fri" ] && /path/to/your/job.sh
Last edited by michaelk; 04-18-2011 at 10:29 AM.
|
|
1 members found this post helpful.
|
04-19-2011, 08:13 AM
|
#7
|
Member
Registered: Mar 2010
Location: INDIA (chennai)
Distribution: centos
Posts: 271
Original Poster
Rep:
|
Thanks michaelk,
it works
I used
04 07 1,15 04 * [ "$(date '+\%w')" == "5" ] && /path/to/your/job.sh
This in cron to execute my job only on 1st and 15th date of April and that too only when it falls on friday.
|
|
|
All times are GMT -5. The time now is 08:12 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|