Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

execute crontab twice daily at 00h and 13:30

Tags:

cron

crontab

i want to execute a script twice daily at 00:00 and 13:30 so i write :

0,30 0,13 * * * 

it seems wrong for me, because like this, the script will fire at 00:00 , 00:30 , 13:00 and 13:30. Any idea ?

like image 554
Wassim Sboui Avatar asked Dec 21 '12 16:12

Wassim Sboui


People also ask

What does 0 * * * * mean in crontab?

0 * * * * -this means the cron will run always when the minutes are 0 (so hourly) 0 1 * * * - this means the cron will run always at 1 o'clock. * 1 * * * - this means the cron will run each minute when the hour is 1.

Can 2 cron jobs run at the same time?

We can run several commands in the same cron job by separating them with a semi-colon ( ; ). If the running commands depend on each other, we can use double ampersand (&&) between them. As a result, the second command will not run if the first one fails.

How do I set up cron to run a file just once at a specific time?

The basic usage of cron is to execute a job in a specific time as shown below. This will execute the Full backup shell script (full-backup) on 10th June 08:30 AM. Please note that the time field uses 24 hours format. So, for 8 AM use 8, and for 8 PM use 20.


2 Answers

Try this-: 00 01,13 * * *

it will run at 1 A.M and 1 P.M

like image 196
Ankush Avatar answered Sep 20 '22 01:09

Ankush


You can't do what you want in one entry, since the two minute definitions will apply for both hour definitions (as you've identified).

The solution is (unfortunately) use two cron entries. One for 00:00 and one for 13:30.

An alternative is perhaps to execute one script at 00:00. That script would execute your original script, then wait 13.5 hours and then execute that script again. It would be easy to do via a simple sleep command, but I think it's unintuitive, and I'm not sure how cron manages such long running processes (what happens if you edit the crontab - does it kill a spawned job etc.)

like image 41
Brian Agnew Avatar answered Sep 20 '22 01:09

Brian Agnew