Using crontab to execute script between 17:00–20:00 for every 10 minutes - linux

I want to send emails to clients every day between 17:00 to 20:00. I want to run my command every 10 minutes in this period.
So the script will be executed 6 times per hour. That's a total of 18 times.
Is this possible with the crontab? How should I write the syntax?

I think this should work:
0/10 17-19 * * * <cmd>
or:
0/10 17,18,19 * * * <cmd>

Related

Set Cron Job Between Specific Times and Frequency

For example I want to run job every 6 minutes between;
16:34 - 18:45
So it must be running on 16:34, 16:40, 16:46 etc. to 18:40.
When I write
34-45 16-18 * * *
It only works between 16:34-16:45 and 18:34-18:45. But I don't want this one.
Is it possible to make this?
Thank you
Hm, where in your cron line is the "every 6 minutes" part? Also, why would your cron go to 18:40, wouldn't 18:42 be the last time you want it to run? Let me know if I'm not understanding the question correctly.
Anyway though, not sure if it's possible in one cron line, but you could always do something like:
34/6 16 * * *
*/6 17 * * *
0,6,12,18,24,30,36,42 18 * * *
Edit: Or, if you have control and are able to edit the file/executable your cron is running you could do:
*/6 16-18 * * * /path/to/myScript
And then at the very beginning of myScript:
if time < 16:34 or time > 18:45:
exit # kill script

How the cron timing is working?

Suppose, current time is 11:42 and i have setup one cron file to run at every 5 minutes.
Then this file will run at which time 11:47 or 11:45?
So basically i am trying to understand that how the cron timing is work?
Edit : it was ran at 11:45, but i don't know the reason behind it
Cron Configuration :
*/5 * * * * wget -O /dev/null http://XXX/index.php?r=controller/action
As you know, cron will run jobs at a specific time.
A cron job will not use the time it was started, only the configuration matters. This means a cron job set to every 5 minutes (like your */5 * * * *) will only ever run at times ending with 0 or 5 (eg: 12:00, 12:05, 12:10), regardless of the time you run it. This makes sense because we want to schedule a job for a specific time.
If you really need a job to run every 5 minutes, with an offset (eg: 11:42, 11:47, 11:52) you will have to give a list in the configuration.
instead of (*/5 * * * *) you would need to use:
(2,7,12,...,57 * * * *), filling ... with all the other numbers.

cronjob which backs off during off-peak hours

I have a php script which crontab executes every 30 minutes, during off-peak hours around 2-7am I don't get much traffic and so I wish to not run the script during these hours.
I'm not sure how to make a cronjob that will do this as I would find it hard to test.
The cronjob I have at the moment looks like this
*/30 * * * * /usr/bin/php /var/www/update/inv.php
*/30 0-1,8-23 * * * /usr/bin/php /var/www/update/inv.php
the range is inclusive, so 0-1 will do 00:30, 01:30, then 8-23 will do 0830 to 2330
ref: http://team.macnn.com/drafts/crontab_defs.html
You can restrict the hours you want the job to run.
*/30 0,1,7-23 * * * /usr/bin/php /var/www/update/inv.php
The times will be every 30 minutes until 0130. It won't run at 0200. The next run will be at 0700 and then every 30 minutes.
There's quite a good article here on how to set up the cron:
http://en.wikipedia.org/wiki/Cron

setup cron tab to specific time of during weekdays

I am trying to setup a cron job on a Ubuntu server. We want the cron job to run the script at certain times of the day and on some specific days of the week. For example, we want to setup a cron job that runs the script with the following sequence:
Execute the script every 2 minutes from 9 am to 2 pm during the weekdays.
This is what I have been able to do so far:
*/2 09-14 * * * /path_to_script
What should I do for the weekdays?
Same as you did for hours:
*/2 09-18 * * 1-5 /path_to_script
0 and 7 stand for Sunday
6 stands for Saturday
so, 1-5 means from Monday to Friday
You state 2pm in your requirement, hour range should end at 14 instead of 18 (which is 6pm).
*/2 9-14 * * 1-5 /path_to_script
man crontab
http://unixhelp.ed.ac.uk/CGI/man-cgi?crontab+5
In fact the last hour you want the script to run is 13:00 to 13:59, so you want:
*/2 9-13 * * 1-5 /path_to_script
meaning the first runtime will be 9:00, then 9:02, and so on until 13:58 which will be the last run as 14:00 is not included.

Cron job question

I want to run a php script every 10 minutes, between the hours of 9:30AM - 4:00PM
I googled before asking, and didn't have any success.
Anyone know how to do this? Or point me in the right direction?
Thank you
Try the following three lines in crontab
0,10,20,30,40,50 10-15 * * * # Every 10 minutes for the hours 10am - 3pm
0 16 * * * # 4pm
30,40,50 9 * * * # and 9:30, 9:40, 9:50
Run it from cron in every 10 minutes, check th date in PHP do nothing if it's outside the range.
*/10 * * * * /usr/bin/php /path/to/your/script.php

Resources