LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
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 05-17-2017, 07:56 AM   #1
yerunkar11
LQ Newbie
 
Registered: Mar 2015
Posts: 24

Rep: Reputation: Disabled
Crontab Issue


Hello,

Thank you in advance.

I want to schedule an cronjob that will run for every 5 minutes past 8:30 am to 5:30 am.

The issue is I can schedule it for 8am to 5pm but cannot define minutes in cronjob.
For this I have done this

*/5 8,9,10,11,12,13,14,15,16,17 * * *
 
Old 05-17-2017, 08:17 AM   #2
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,635

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
Quote:
Originally Posted by yerunkar11 View Post
I want to schedule an cronjob that will run for every 5 minutes past 8:30 am to 5:30 am. The issue is I can schedule it for 8am to 5pm but cannot define minutes in cronjob. For this I have done this

*/5 8,9,10,11,12,13,14,15,16,17 * * *
The first field is minutes, and you've successfully scheduled it to run every five minutes between 8AM and 5 PM. I'm assuming you want it to start at 8:30 AM, and end at 5:30 PM, which is your problem, right?

Handy cron field explanation...suitable for inclusion in your crontab file
Code:
# *     *     *   *    *        command to be executed
# -     -     -   -    -
# |     |     |   |    |
# |     |     |   |    +----- day of week (0 - 6) (Sunday=0)
# |     |     |   +------- month (1 - 12)
# |     |     +--------- day of        month (1 - 31)
# |     +----------- hour (0 - 23)
# +------------- min (0 - 59)
Personally, I'd define three jobs:
Code:
30-59/5  8    * * * job 
*/5      9-17 * * * job
0-30/5   17   * * * job
That will run the job starting at 8:30 AM every five minutes, until 9 AM. That's when the second line (9 AM-5 PM) comes into play, running it every five minutes. Then from 5 PM to 5:30 PM (every five minutes), the third line applies.
 
1 members found this post helpful.
Old 05-17-2017, 08:22 AM   #3
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669
Presumably you meant 5:30 PM rather than 5:30 AM.

You don't need to enumerate all the hours in a range so your original:
*/5 8,9,10,11,12,13,14,15,16,17 * * *

Should more simply be written as:
*/5 8-17 * * *

I'm assuming you mean you want to run at 8:30, 8:35, 8:40, 8:45, 8:55 and 17:00 17:05, 17:10, 17:15, 17:20, 17:25 & 17:30 but then ever 5 minutes all other hours.

You'd need to add multiple cron lines to achieve that

First for hours 09 to 16 (9 AM to 4 PM) you'd do the time spec:
*/5 9-16 * * *

For your start at 8:30AM :
30,35,40,45,50,55 8 * * *

For your end at 5:30 PM
00,05,10,15,20,25,30 17 * * *
 
1 members found this post helpful.
Old 05-17-2017, 08:23 AM   #4
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,701

Rep: Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895
I would just use three separate cron jobs.

30-55/5 8 * * *
*/5 9-16 * * *
0-30/5 17 * * *

To late...
 
1 members found this post helpful.
Old 05-18-2017, 05:19 AM   #5
yerunkar11
LQ Newbie
 
Registered: Mar 2015
Posts: 24

Original Poster
Rep: Reputation: Disabled
Thank you all..

All solution solved my issue.

in the end I'll be adding 3 Cronjobs
 
  


Reply



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] crontab issue stockton Linux - General 6 01-16-2015 04:14 AM
[SOLVED] Crontab issue pinga123 Linux - General 2 03-17-2011 01:56 AM
crontab issue,need help aditya_moon Linux - Newbie 2 02-07-2011 10:54 PM
crontab issue adnanm Linux - Newbie 1 03-16-2007 02:28 AM
crontab issue houssamfarag Red Hat 2 06-27-2006 11:56 PM

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

All times are GMT -5. The time now is 05:06 PM.

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