执行shell脚本后,其他脚本得到成功执行 [英] Execute Shell script after other script got executed successfully

查看:146
本文介绍了执行shell脚本后,其他脚本得到成功执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题陈述: -

我有,我想只有当previous脚本得到成功执行的执行四种shell脚本。而我运行它像这样目前 -

  ./ verify-export-realtime.shSH -x lca_query.shSH -x liv_query.shSH -x lqu_query.sh

所以,为了使previous脚本后运行其他脚本是成功的。我需要做类似下面?我不知道我是否正确?如果任何脚本得到了失败,因为任何理由将打印为失败,由于某种原因,吧?

  ./ verify-export-realtime.shRET_VAL_STATUS = $?
回声$ RET_VAL_STATUS
如果[$ RET_VAL_STATUS -ne 0];然后
回声失败是由于某种原因
出口
科幻SH -x lca_query.shRET_VAL_STATUS = $?
回声$ RET_VAL_STATUS
如果[$ RET_VAL_STATUS -ne 0];然后
回声失败是由于某种原因
出口
科幻SH -x liv_query.shRET_VAL_STATUS = $?
回声$ RET_VAL_STATUS
如果[$ RET_VAL_STATUS -ne 0];然后
回声失败是由于某种原因
出口
科幻
SH -x lqu_query.sh


解决方案

外壳提供了一个运营商&放大器;&安培; 做的正是这一点。所以,你可以写:

  ./ verify-export-realtime.sh和放大器;&安培; \\
SH -x lca_query.sh&放大器;&安培; \\
SH -x liv_query.sh&放大器;&安培; \\
SH -x lqu_query.sh

或者你可以摆脱线延续的( \\ ),这一切写在一行

  ./ verify-export-realtime.sh和放大器;&安培; SH -x lca_query.sh&放大器;&安培; SH -x liv_query.sh&放大器;&安培; SH -x lqu_query.sh

如果你想知道它有多远了,你可以添加,只是设置一个变量额外的命令:

 做= 0
./verify-export-realtime.sh&功放;&安培;做= 1&安培;&安培;
SH -x lca_query.sh&放大器;&安培;做= 2和;&放大器;
SH -x liv_query.sh&放大器;&安培;做= 3和;&放大器;
SH -x lqu_query.sh&放大器;&安培;做= 4

$做过结尾处的值告诉你有多少命令成功完成。 $?将设置到最后一个命令运行的退出值(这是失败的),或 0 如果所有的成功

Problem Statement:-

I have four shell script that I want to execute only when the previous script got executed successfully. And I am running it like this currently-

./verify-export-realtime.sh

sh -x lca_query.sh

sh -x liv_query.sh

sh -x lqu_query.sh

So In order to make other scripts run after previous script was successful. I need to do something like below? I am not sure whether I am right? If any script got failed due to any reason it will print as Failed due to some reason right?

./verify-export-realtime.sh

RET_VAL_STATUS=$?
echo $RET_VAL_STATUS
if [ $RET_VAL_STATUS -ne 0 ]; then
echo "Failed due to some reason"
exit
fi

sh -x lca_query.sh

RET_VAL_STATUS=$?
echo $RET_VAL_STATUS
if [ $RET_VAL_STATUS -ne 0 ]; then
echo "Failed due to some reason"
exit
fi

sh -x liv_query.sh

RET_VAL_STATUS=$?
echo $RET_VAL_STATUS
if [ $RET_VAL_STATUS -ne 0 ]; then
echo "Failed due to some reason"
exit
fi


sh -x lqu_query.sh

解决方案

The shell provides an operator && to do exactly this. So you could write:

./verify-export-realtime.sh && \
sh -x lca_query.sh && \
sh -x liv_query.sh && \
sh -x lqu_query.sh

or you could get rid of the line continuations (\) and write it all on one line

./verify-export-realtime.sh && sh -x lca_query.sh && sh -x liv_query.sh && sh -x lqu_query.sh

If you want to know how far it got, you can add extra commands that just set a variable:

done=0
./verify-export-realtime.sh && done=1 &&
sh -x lca_query.sh && done=2 &&
sh -x liv_query.sh && done=3 &&
sh -x lqu_query.sh && done=4

The value of $done at the end tells you how many commands completed successfully. $? will get set to the exit value of the last command run (which is the one that failed), or 0 if all succeeded

这篇关于执行shell脚本后,其他脚本得到成功执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆