Unix/Linux Go Back    


Solaris The Solaris Operating System, usually known simply as Solaris, is a Unix-based operating system introduced by Sun Microsystems. The Solaris OS is now owned by Oracle.

How to run cron entry every 5 min during office hours only?

Solaris


Reply    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 12-21-2016
fretagi fretagi is offline
Registered User
 
Join Date: Oct 2011
Last Activity: 3 April 2017, 5:57 AM EDT
Posts: 390
Thanks: 95
Thanked 2 Times in 2 Posts
How to run cron entry every 5 min during office hours only?

Hi

I need to setuop a cron entry to run every 5 min, only in office hours (between 8:00AM to 18:00PM, I did the following:

Code:
0,5,10,15,20,25,30,35,40,45,50,55 8,9,10,11,12,13,14,15,16,17,18 * * * /home/xxx/zzz.ksh

But somehow does not work.
Could it be wrong?
Sponsored Links
    #2  
Old Unix and Linux 12-21-2016
hicksd8 hicksd8 is offline Forum Advisor  
Registered User
 
Join Date: Feb 2012
Last Activity: 28 April 2017, 11:47 AM EDT
Location: Devon, UK
Posts: 1,380
Thanks: 170
Thanked 348 Times in 291 Posts
I reckon the hours field should be "8-17" so first run at 0800 and last at 1755.

Use a hypen to denote a range of hours.

---------- Post updated at 11:59 AM ---------- Previous update was at 11:54 AM ----------

Of course, that will run 7 days a week unless you specify a 'day of week' range instead of the *
The Following User Says Thank You to hicksd8 For This Useful Post:
fretagi (12-21-2016)
Sponsored Links
    #3  
Old Unix and Linux 12-21-2016
fretagi fretagi is offline
Registered User
 
Join Date: Oct 2011
Last Activity: 3 April 2017, 5:57 AM EDT
Posts: 390
Thanks: 95
Thanked 2 Times in 2 Posts
I have change now, waiting to see the results (my time in GMT +2)
    #4  
Old Unix and Linux 12-21-2016
rbatte1 rbatte1 is offline Forum Staff  
Root armed
 
Join Date: Jun 2007
Last Activity: 27 April 2017, 11:56 AM EDT
Location: Lancashire, UK
Posts: 3,080
Thanks: 1,287
Thanked 590 Times in 534 Posts
Some cron servers also accept this syntax:-
Code:
*/5 8-17 * * * /your/command/here

This is the step from the zero of that item, so should be a factor of the maximum, e.g. 2, 3, 4, 6 or 12 for the hours. I can't see a neat way to do it every 10 minutes replacing 5,15,25,35,45,55, although you could build it something like this:-

Code:
*/10 * * * * bash -c "/bin/sleep 300 ; /your/command/here"

The best place to check if your host supports it is the manual page for the file crontab.
Often this can be found with man 5 crontab but check with man -k crontab to get the various options for pages you can read, such as Unix.com man page for crontab file




I hope that this helps,
Robin

Last edited by rbatte1; 12-21-2016 at 08:05 AM.. Reason: Smartened URL display
The Following User Says Thank You to rbatte1 For This Useful Post:
fretagi (12-21-2016)
Sponsored Links
    #5  
Old Unix and Linux 12-21-2016
fretagi fretagi is offline
Registered User
 
Join Date: Oct 2011
Last Activity: 3 April 2017, 5:57 AM EDT
Posts: 390
Thanks: 95
Thanked 2 Times in 2 Posts
the
Code:
*/5 * * * * /your/command/here

does not work on solaris 10, only in linux
Sponsored Links
    #6  
Old Unix and Linux 12-21-2016
hicksd8 hicksd8 is offline Forum Advisor  
Registered User
 
Join Date: Feb 2012
Last Activity: 28 April 2017, 11:47 AM EDT
Location: Devon, UK
Posts: 1,380
Thanks: 170
Thanked 348 Times in 291 Posts
Don't forget, you should be using the 'crontab' command to enter cron jobs. If you're editing the crontab file directly yourself then cron may not know about the changes for up to 24 hours and therefore the job(s) won't run. Otherwise restart the cron daemon from the command line to alert it of the changes.
The Following User Says Thank You to hicksd8 For This Useful Post:
fretagi (12-21-2016)
Sponsored Links
    #7  
Old Unix and Linux 12-21-2016
rbatte1 rbatte1 is offline Forum Staff  
Root armed
 
Join Date: Jun 2007
Last Activity: 27 April 2017, 11:56 AM EDT
Location: Lancashire, UK
Posts: 3,080
Thanks: 1,287
Thanked 590 Times in 534 Posts
I've found this document that suggests that it has an extension to allow this:-
Code:
5/10 * * * * /you/command/here

.... but there is no clue which variant this might be deployed in. It is rejected for me on CentOS 6 with this:-
Code:
crontab: installing new crontab
"/tmp/crontab.cVRcNc":3: bad minute
errors in crontab file, can't install.
Do you want to retry the same edit?

It might be useful, but I'd prefer a fully functional external scheduler that allows for structured job planning and dependencies unless it's simple jobs running on many and widely distributed servers. Horses for courses I suppose. Linux


Robin
Sponsored Links
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to Disabling cron for few hours each day rakeshkumar UNIX for Dummies Questions & Answers 1 10-16-2012 08:41 AM
cron off by 5 hours mshilling AIX 4 09-23-2011 03:30 PM
cron entry everurs789 UNIX for Dummies Questions & Answers 3 01-24-2011 10:53 AM
User entry in both cron.allow and cron.deny ksvaisakh Solaris 5 12-25-2009 12:39 PM
Cron job for every five minutes and between hours aemunathan Shell Programming and Scripting 1 12-06-2009 07:15 AM



All times are GMT -4. The time now is 12:04 PM.