Crontab new line just don't work as it should? - cron

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

Related

Created cron job to run every 2 mint

I have configured cron job but it's not working.
I wanted to run the myfile.sh script for every 2 mint and below are my configuration in crontab.
# m h dom mon dow comman
2 * * * * /home/ubuntu/myfile.sh
myfile.sh is executable and contains below lines of code
#!/bin/bash
mysqldump -u[user] -p[password] --single-transaction --routines --triggers --all-databases > /home/ubuntu/backup_db10.sql
Is there anywhere we need to add configure anything?
You're running the script at two minutes past every hour. As in 1:02, 2:02 and so on.
You can change it to something like
*/2 * * * * /home/ubuntu/myfile.sh
to run it every two minutes.
A bit more info can be found here.

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

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>

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

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

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