cPanel - 我可以在一个cron作业中运行多个文件吗?

cPanel  - 我可以在一个cron作业中运行多个文件吗?

问题描述:

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

我目前在不同时间运行的cPanel cron jobs部分设置了5个php文件。 理想情况下,我希望在每个作业完成后按顺序运行这些作业。 是否有一个命令我可以做到这一点? p>

例如,我不知道语法,但我可以这样做: p>

  / usr / local / bin / php -f /home/public_html/fileA.php THEN /home/public_html/fileB.php
div>

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

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.

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.