Cron job minute to tomorrow

I am going to invoke a PHP file call through a curl in a schedule. I think the script will run every 23:59:59 or just a minute before the day turns tomorrow. What is the best approach for this? Pretty embarrassed about cron settings.

I need to make sure that I run exactly one second before the next day.

+6
source share
4 answers

To run the script every day at 23:59:00, use the following:

59 23 * * * root /path_to_file_from_root 

Seconds cannot be determined using Cron , but it should do it for you.

To execute the script at 23:59:59, use the PHP sleep() function to delay the execution of the script by 59 seconds. I would advise in 58 seconds, just to make sure the script doesn't linger until midnight.

It is very simple, you can make it a little more complicated and run tests to ensure that the script always starts at 23:59:59, getting the time and lingering accordingly. However, this is not necessary.

 <?php // Any work that the script can do without altering the database, do here // Delay the script by 58 seconds sleep(58); // Carry on with the rest of the script here, database updates etc ?> 
+7
source
 Minutes [0-59] | Hours [0-23] | | Days [1-31] | | | Months [1-12] | | | | Days of the Week [Numeric, 0-6] | | | | | * * * * * home/path/to/command/the_command.sh 59 23 * * * home/path/to/command/the_command.sh 
+13
source

Start editing crontab with

 crontab -e 

or

 vi /etc/cronatb 

It depends on the distribution.

 59 23 * * * root /path/to/your/php/file.php 

Note that the β€œroot” column means the name of the user under which the task is run, it may not be available on your system.

Try to run

 man crontab 

for more details

+1
source

You can configure it to run exactly 23:59:00 every day, take a look at the examples by setting it here . In particular, see Example No. 1, which explains how to install the crown within a certain time.

0
source

Source: https://habr.com/ru/post/912031/


All Articles