Linux - ServerThis 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.
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.
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)
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.
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 * * *
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.