Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set a cron job to run at a exact time?

Tags:

cron

I have a cron job that runs once a day. But I would like to make it run at midnight or other time exactly.

like image 958
ian Avatar asked Mar 04 '11 23:03

ian


People also ask

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.

How do I change the time on a cron job?

Thankfully, you can configure a specific timezone for your Cron job as follows: First, you need to export the TZ variable in your Shell script before any other Shell entries. Next, access your crontab and use the crontab environment variable CRON_TZ at the start of the crontab file.

What is the use of * * * * * In cron?

It is a wildcard for every part of the cron schedule expression. So * * * * * means every minute of every hour of every day of every month and every day of the week .

Can Cronjobs run at the same time?

Yes, it is perfectly acceptable to have cron schedule multiple jobs at the same time. Computers do nothing simultaneously, however, and they will be started in the order present in the cron table.


2 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) 

Hope it helps :)

--

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)
like image 127
Bruno J. Araujo Avatar answered Sep 21 '22 17:09

Bruno J. Araujo


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 * * * 
like image 36
Brandon Frohbieter Avatar answered Sep 20 '22 17:09

Brandon Frohbieter