Last active
August 21, 2019 08:43
-
-
Save noname007/9fd71eba97619211e76a9586741d5281 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#https://blog.csdn.net/mydriverc2/article/details/79011438 | |
set -x | |
cmd="$@" | |
r=$(ps aux|grep "${cmd}" | grep -v "$0"|grep -v 'grep') | |
if [ "x${r}" == 'x' ]; then | |
echo "exec:[${cmd} &]" | |
$($@) & | |
sleep 5 | |
echo "$?" | |
r=$(ps aux|grep "${cmd}" | grep -v "$0"|grep -v 'grep') | |
if [ "x${r}" == 'x' ]; then | |
wait $! | |
ret_code=$? | |
echo "${ret_code}, $!" | |
exit ${ret_code} | |
fi | |
fi | |
背景&目标:
shell 中的 & 会掩盖掉 原本脚本运行的状态码。
如果 dcron 拉起来失败,这段代码可以传递出来原本脚本的进程的退出错误码。
如果后台运行进程没有拉起来,也能感知到失败了,继续复用 dcron 的邮件、短信
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
success
failed