【问题标题】:CRON JOB scheduling while checking the other scripts statusCRON JOB 调度同时检查其他脚本状态
【发布时间】:2015-12-21 21:45:25
【问题描述】:

我有一个场景,我有三个 shell 脚本,其中 2 个脚本应该同时启动,一旦前两个脚本完成,第三个脚本应该启动。 前任: Test1.sh 和 Test2.sh 应该并行启动,当两个脚本都成功完成后,Test3.sh 应该启动。有人可以帮我解决这个问题。

【问题讨论】:

    标签: bash shell cron


    【解决方案1】:

    你应该使用这个语法(不管 cron 上下文):

    test1.sh & test2.sh ; test3.sh
    

    我不确定 cron 在其命令中是否接受 ;。如果没有,你可以改用这个:

    (test1.sh & test2.sh) && test3.sh
    

    然而,这需要 (test1.sh & test2.sh) 返回 0 返回码,test3.sh 才能被执行。
    看起来(command1 & command2) 将返回command2 的结果(我试过(exit 1 & exit 0) ; echo $? 并且它回显0,而(exit 0 & exit 1) ; echo $? 返回1。

    【讨论】:

    • 谢谢亚伦。以下语法有效。 test1.sh & test2.sh ; test3.sh
    • @SurenderKumar 不客气,很高兴为您提供帮助。如果它解决了您的问题,请接受此答案。
    猜你喜欢
    • 1970-01-01
    • 2012-09-13
    • 1970-01-01
    • 2011-05-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-04
    • 1970-01-01
    相关资源
    最近更新 更多