i have two cronjobs, i want to run the two cronjobs at a small gap of ten minutes. once in two days, at 0100 hours and 0110 hours
this is what iam trying.
0 1 */2 * * job1.sh
10 1 */2 * * job2.sh
job1 is not working as expected. it runs twice everyday.
job2 runs as expected (once in two days).
what am i doing wrong?
You need to add the binary executing the script, as well as the complete route to your file:
0 1 */2 * * /bin/sh /route/to/your/file/job1.sh
10 1 */2 * * /bin/sh /route/to/your/file/job2.sh
/bin/sh can be another thing, just get it from which sh.
Related
I have set crontab on every 24 hrs should run a single php command, instead it runs the command like 20+ times a day. It doesn't work as it should. Is it really wrong?
* */12 * * * php /var/www/mything.php
I added this on new crontab line? Is the line correct?
0 */12 * * * php /var/www/mything.php
should run the command every 12 hours (0 and 12 o'clock)
0 12 * * * php /var/www/mything.php
should run the command at 12 o'clock every day
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
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
How can i set three cron jobs for every two days interval but not runs all.
This is is my three cron job process:
0 20 */2 * * /usr/local/bin/ruby /var/www/html/data_download1.rb >/dev/null 2>&1
0 20 */2 * * /usr/local/bin/ruby /var/www/html/data_download2.rb >/dev/null 2>&1
0 20 */2 * * /usr/local/bin/ruby /var/www/html/data_download3.rb >/dev/null 2>&1
You can use 1-31/2 for one task and 2-30/2 for the other to specify alternating days. This will fail on months with odd numbers of days as the 1-31/2 job will run twice in a row.
If you absolutely must have it right, you can check whether the number of days since a particular date is odd or even and have one script abort if it's odd and the other abort if it's even.
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