Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run cron job when another cron job finishes?

Tags:

cron

jobs

How do I set up a cron job (cron2.php) to run after and only after a cron job (cron1.php) runs successfully?

like image 587
Paul Avatar asked Jul 03 '11 20:07

Paul


2 Answers

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 ;).

like image 153
borrible Avatar answered Oct 16 '22 04:10

borrible


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.

like image 30
fabspro Avatar answered Oct 16 '22 05:10

fabspro