Reputation: 385
How do I set up a cron job (cron2.php) to run after and only after a cron job (cron1.php) runs successfully?
Upvotes: 6
Views: 12874
Reputation: 1679
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.
Upvotes: 4
Reputation: 17356
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 ;
).
Upvotes: 16