I am about to trigger a call to a PHP file via curl in a schedule basis. I am thinking of having the script to be executed every 23:59:59 or simply a minute before the day turns tomorrow. Any best approach for this? Quite confused still on the cron settings.
I need to ensure that I run at exactly a second before the next day.
What does * mean in Cron? The asterisk * is used as a wildcard in Cron. * sets the execution of a task to any minute, hour, day, weekday, or month.
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.
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.
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
To Execute a script every day at 23:59:00, use the following:
59 23 * * * root /path_to_file_from_root
Seconds cannot be defined using Cron, but this should do 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 58 seconds though, just to make sure the script doesn't delay until after midnight.
This is very basic, you could make it a little more complex and run tests to ensure that the script is always run at 23:59:59 by retrieving the time and delaying appropriately. This should not be necessary though.
<?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
?>
Start crontab editing by
crontab -e
or by
vi /etc/cronatb
It depends on distro.
59 23 * * * root /path/to/your/php/file.php
Note that "root" column mean name of user under which to start job, maybe will not available on your system.
Try to run
man crontab
for more details
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With