How do I set up a cron job (cron2.php) to run after and only after a cron job (cron1.php) runs successfully?
To do two commands, one following the other, just use ;
. For example, you'll see that
sleep 2; ls
will pause for two seconds and then do an ls
. Do the same in your crontab.
If the second job relies on the first being successful, use the &&
notation (in place of the ;
).
If it's practical you could use shell_exec or include within the first php file to run the second file. If this is placed at the end of the first file, it will only be executed if the script successfully reaches that point, and you can use php code to verify that the first part completed successfully.
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