0

I have 5 php files currently set up in my cPanel cron jobs section running at different times. Ideally, I would like to run these jobs sequentially as each one finishes. Is there a command I can do to make that happen?

For example, I don't know the syntax but can I do something like:

/usr/local/bin/php -f /home/public_html/fileA.php THEN /home/public_html/fileB.php
Keith C.
  • 365
  • 1
  • 5
  • 15

3 Answers3

0

Please see the answer here:

Running two commands sequentially in a cron job?

If you'd rather read it here, basically you can separate the commands with "&&" and one will run when the other finishes. Or, a more logical solution to me, is to make one file and have it execute each of the files you want it to.

Community
  • 1
  • 1
ckimbrell
  • 537
  • 3
  • 9
0

yes, there is, you can run multiple cron jobs on single line, and each job will executed when first one is finished.

I recommend you to read this

you need to put && between the crons

So your cron will look something like this.

/home/public_html/fileA.php && /home/public_html/fileB.php && /home/public_html/fileC.php

and so on, add whatever number you want to. As a note, the && will only run the next command if the current command completes successfully. If you have a script that may error out, simply use a ; which is a line buffer. Do not use a line buffer if you are moving, tarring, or deleting.

Lando
  • 419
  • 3
  • 8
Mubin
  • 4,325
  • 5
  • 33
  • 55
  • The `&&` specifically means 'and if this command finishes successfully'. If the first script might fail, simply use a `;` which is just a line-buffer. – Lando Nov 04 '15 at 22:06
  • 1
    great, edit the post please, so that me and OP should gain some more knowledge :) – Mubin Nov 04 '15 at 22:07
0

You can use "&&" between each call like so:

/usr/local/bin php -f /home/public_html/fileA.php && /usr/local/bin php -f /home/public_html/fileB.php && /usr/local/bin php -f /home/public_html/fileC.php

...and so on. :)

MrWolf
  • 690
  • 1
  • 6
  • 6