I have a cron job that runs once a day. But I would like to make it run at midnight or other time exactly.
4 Answers
You can also specify the exact values for each gr
0 2,10,12,14,16,18,20 * * *
It stands for 2h00, 10h00, 12h00 and so on, till 20h00.
From the above answer, we have:
The comma, ",", means "and". If you are confused by the above line, remember that spaces are the field separators, not commas.
And from (Wikipedia page):
* * * * * command to be executed
┬ ┬ ┬ ┬ ┬
│ │ │ │ │
│ │ │ │ │
│ │ │ │ └───── day of week (0 - 7) (0 or 7 are Sunday, or use names)
│ │ │ └────────── month (1 - 12)
│ │ └─────────────── day of month (1 - 31)
│ └──────────────────── hour (0 - 23)
└───────────────────────── min (0 - 59)
EDIT:
- don't miss the 1st 0 (zero) and the following space: it means "the minute zero", you can also set it to 15 (the 15th minute) or expressions like */15 (every minute divisible by 15, i.e. 0,15,30)

- 20,030
- 7
- 43
- 238

- 1,493
- 1
- 9
- 5
-
2
-
-
2@YumYumYum There is space between 0 and next number, so it represent minute and next represent hour. – Abhishek Sachan Sep 16 '16 at 07:26
-
Ah! I mean it... (e.g. 02:00 as start time, ending 20:00) :) am I missing something or was just the space? – Bruno J. Araujo Oct 04 '16 at 15:06
-
1Remember that you can also use steps by using slash. So, for even-numbered hours, the example in the answer can be simplified to 0 2-20/2 * * *. **Note** this doesn't help with the OP question of "once per day", but given the high votes for the answer, it may help others with general crontab syntax questions that land on this answer. Also http://crontab.guru really helps with cron syntax issues. _Disclosure: I'm involved in the project_ – HeyZiko Oct 11 '16 at 16:12
check out
http://www.thesitewizard.com/general/set-cron-job.shtml
for the specifics of setting your crontab directives.
45 10 * * *
will run in the 10th hour, 45th minute of every day.
for midnight... maybe
0 0 * * *

- 17,563
- 3
- 40
- 62
-
3what if I dont want repetitions..only want the job to execute once @10:45? – user2176576 Sep 16 '14 at 05:23
-
-
Very helpful visual constructor
First example cron task:
5 4 * * *
runs at:
04:05
Second example cron task:
5 */1 * * *
runs at:
minute 5 past every hour

- 11,718
- 17
- 75
- 74
My use case is that I'm on a metered account. Data transfer is limited on weekdays, Mon - Fri, from 6am - 6pm. I am using bandwidth limiting, but somehow, data still slips through, about 1GB per day!
I strongly suspected it's sickrage or sickbeard, doing a high amount of searches. My download machine is called "download." The following was my solution, using the above,for starting, and stopping the download VM, using KVM:
# Stop download Mon-Fri, 6am
0 6 * * 1,2,3,4,5 root virsh shutdown download
# Start download Mon-Fri, 6pm
0 18 * * 1,2,3,4,5 root virsh start download
I think this is correct, and hope it helps someone else too.

- 88,222
- 31
- 159
- 162

- 11
- 1
-
You can also simplify your days to a range: 0 6 * * 1-5. Here's what crontab.guru says for both options: Distinct List = http://crontab.guru/#0_6_%2A_%2A_1,2,3,4,5 Range = http://crontab.guru/#0_6_%2A_%2A_1-5 – HeyZiko Oct 11 '16 at 16:07