简体   繁体   English

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

[英]cPanel - Can I run multiple files within one cron job?

I have 5 php files currently set up in my cPanel cron jobs section running at different times. 我目前在不同时间运行的cPanel cron作业部分中设置了5个php文件。 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

Please see the answer here: 请在这里查看答案:

Running two commands sequentially in a cron job? 在cron作业中顺序运行两个命令?

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. 是的,您可以在一行上运行多个cron jobs ,并且每个作业都会在第一个作业完成后执行。

I recommend you to read this 我建议你读这个

you need to put && between the crons 您需要将&&放在crons之间

So your cron will look something like this. 所以您的cron看起来会像这样。

/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. 如果要移动,涂油或删除,请不要使用行缓冲区。

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 / 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. ...等等。 :) :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM