我想通过外壳检查sqlplus命令的两个输出是否匹配。因此,我循环执行,直到捕获到该输出的变量相等为止,然后结束循环,然后执行下一组指令。
以下提到的循环均未按预期运行。
我希望实时获取testSeq
和expectedSeq
的数据,然后进行比较以检查数据,如果它们相等,请退出并进行下一步。
testSeq=`sqlplus -S user/xxxxxxxxx@${primary} << EOF
set heading off feedback off pagesize 0 verify off echo off numwidth 15
select max(ARCHIVED_SEQ#) from v\\$ARCHIVE_DEST_STATUS;
EOF`
expectedSeq=`sqlplus -S user/xxxxxxxxx@${DR}<< EOF
set heading off feedback off pagesize 0 verify off echo off numwidth 15
select max(APPLIED_SEQ#) from V\\$ARCHIVE_DEST_STATUS;
EOF`
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
while (true)
do
while do;
testSeq=`sqlplus -S user/xxxxxxxxx@${primary} << EOF
set heading off feedback off pagesize 0 verify off echo off numwidth 15
select max(ARCHIVED_SEQ#) from v\\$ARCHIVE_DEST_STATUS;
EOF`
expectedSeq=`sqlplus -S user/xxxxxxxxx@${DR}<< EOF
set heading off feedback off pagesize 0 verify off echo off numwidth 15
select max(APPLIED_SEQ#) from V\\$ARCHIVE_DEST_STATUS;
EOF`
if [[ "$testSeq" != "$expectedSeq" ]]
then
echo "$DR sync is in Progress." | mailx -s "$DR Refresh update" [email protected]
else
sleep 20
echo "$DR is in sync with ${PRIMARY} and ready to be switched to Snapshot DR" | mailx -s "$DR Refresh update" [email protected]
done
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
while [[ "$testSeq" != "$expectedSeq" ]]; do
echo "$DR sync is in Progress." | mailx -s "$DR Refresh update" [email protected]
sleep 20
done
echo "$DR is in sync with ${PRIMARY} and ready to be switched to Snapshot DR" | mailx -s "$DR Refresh update" [email protected]
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
until [ "$expectedSeq" -eq "$testSeq" ]; do
echo "$DR sync is in Progress." | mailx -s "$DR Refresh update" [email protected]
sleep 5
if [ $? -eq 0 ]; then
break
fi
done
echo "$DR is in sync with ${PRIMARY} and ready to be switched to Snapshot DR" | mailx -s "$DR Refresh update" [email protected]
感谢所有帮助。在此先感谢
这应该与bash一起使用,我没有测试ksh:
expectedSeq=`sqlplus -S user/xxxxxxxxx@${DR} <<EOF
set heading off feedback off pagesize 0 verify off echo off numwidth 15
select max(APPLIED_SEQ#) from V\\$ARCHIVE_DEST_STATUS;
EOF`
testSeq=
while [[ $testSeq != $expectedSeq ]]; do
if [[ -n testSeq ]]; then
echo "$DR sync is in Progress."
sleep 20
fi
testSeq=`sqlplus -S user/xxxxxxxxx@${primary} <<EOF
set heading off feedback off pagesize 0 verify off echo off numwidth 15
select max(ARCHIVED_SEQ#) from V\\$ARCHIVE_DEST_STATUS;
EOF`
# todo: handle failures
done
echo "$DR is in sync with ${primary} and ready to be switched to Snapshot DR"
可以在循环外定义期望的输出,只要该表在此过程中没有变化。您应该为grepping输出中的错误做好准备,以防查询失败。