简体   繁体   English

如何在Shell脚本中使用循环语句

[英]How to use loops statements in shell scripting

I wrote a script to execute a control. 我编写了一个脚本来执行控件。 In the script, I am checking for an error. 在脚本中,我正在检查错误。 If error =200 then again rerun the control after five minutes. 如果error = 200,则五分钟后再次重新运行该控件。 Now the script is getting exist irrespective of error. 现在,无论错误如何,脚本都将存在。 Below is my script. 下面是我的脚本。

. $HOME/infogix.env
#!/bin/bash
SCRIPT_NAME=$(basename $0)
INFOGIX=info/IA83/Client/bin/runcp.sh

check_for_errors()
{
if  [ "${1}" -ne "0" ]; then
exit 1
fi
}
$RUNCP_HOME -c $1 IA -entity NGN_MKTG_CNCT_HIST_FILECNT_CE -point FILE_EXTRACT_CP
check_for_errors $?

echo "Processing Complete for ${SCRIPT_NAME}"
exit 0
#EOF

You aren't actually using a loop in your script. 您实际上并没有在脚本中使用循环。

#!/bin/bash

. "$HOME/infogix.env"
script_name="$(basename "$0")"
info_gix="info/IA83/Client/bin/runcp.sh"

function run_runcp()
{
    $RUNCP_HOME -c "$1" IA -entity NGN_MKTG_CNCT_HIST_FILECNT_CE -point FILE_EXTRACT_CP;
    if [ "$?" -eq 200 ]; then
        return 0
    else
        return 1
    fi
}

# If RUNCP_HOME returns 0, then the loop will stop. Otherwise, it will sleep for 5 minutes then continue
while run_runcp "$1"; do
    sleep 300 # Five minutes
done

echo "Processing Complete for ${script_name}"
exit 0

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

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