循环中的 sqlplus - unix
sqlplus within a loop - unix
有没有一种方法可以在一个循环中发送多个 sqlplus 命令,但等待一个成功 运行 以便下一个命令开始?
这是我的代码示例。我试图添加 sleep 15,因为我要执行的功能需要 10-20 秒到 运行。我想摆脱那个 15s 常量并使它们 运行 一个接一个。
if [ "$#" -eq 1 ]; then
checkUser ""
while read line; do
sqlplus $user/$pass@$server $line
sleep 15
done < "$wrapperList"
fi
while
循环中的指令按顺序执行。这相当于这样做,使用 ;
链接指令:
sqlplus $user/$pass@$server $line1
sqlplus $user/$pass@$server $line2
所以你不需要这里的sleep 15
,因为sqlplus
命令不会被并行调用。您已经采用的方法是一个接一个地调用它们。
注意:如果第一行没有 return 正确,最好停止 运行ning,使用 &&
表示:运行 只有前一个 return 代码是 0
sqlplus $user/$pass@$server $line1 &&\
sqlplus $user/$pass@$server $line2
要在 while 循环中使用它:
checkUser ""
while read line; do
sqlplus $user/$pass@$server $line
RET_CODE=$? # check return code, and break if not ok.
if [ ${RET_CODE} != 0 ]; then
echo "aborted." ; break
fi
done < "$wrapperList"
另一方面, 当你想要并行 运行 时,语法是不同的,就像这里:Unix shell script run SQL scripts in parallel
有没有一种方法可以在一个循环中发送多个 sqlplus 命令,但等待一个成功 运行 以便下一个命令开始? 这是我的代码示例。我试图添加 sleep 15,因为我要执行的功能需要 10-20 秒到 运行。我想摆脱那个 15s 常量并使它们 运行 一个接一个。
if [ "$#" -eq 1 ]; then
checkUser ""
while read line; do
sqlplus $user/$pass@$server $line
sleep 15
done < "$wrapperList"
fi
while
循环中的指令按顺序执行。这相当于这样做,使用 ;
链接指令:
sqlplus $user/$pass@$server $line1
sqlplus $user/$pass@$server $line2
所以你不需要这里的sleep 15
,因为sqlplus
命令不会被并行调用。您已经采用的方法是一个接一个地调用它们。
注意:如果第一行没有 return 正确,最好停止 运行ning,使用 &&
表示:运行 只有前一个 return 代码是 0
sqlplus $user/$pass@$server $line1 &&\
sqlplus $user/$pass@$server $line2
要在 while 循环中使用它:
checkUser ""
while read line; do
sqlplus $user/$pass@$server $line
RET_CODE=$? # check return code, and break if not ok.
if [ ${RET_CODE} != 0 ]; then
echo "aborted." ; break
fi
done < "$wrapperList"
另一方面, 当你想要并行 运行 时,语法是不同的,就像这里:Unix shell script run SQL scripts in parallel