Paul
Paul

Reputation: 385

How to run cron job when another cron job finishes?

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

Answers (2)

fabspro
fabspro

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

borrible
borrible

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

Related Questions