我尝试跑步 美好的一天。我在远程服务器上运行该脚本以进行db_link测试。该脚本连接到数据库,并执行DB_LINK测试。在快速执行查询的服务器上,我看到了结果,在运行SQL查询时间更长的服务器上,ssh不会等待sql脚本执行并继续工作。我怎么能期望sql查询完成,然后继续执行脚本。
FILE=`cat db_list.txt | sort -u`
for I in $FILE
do
echo $I
if [ -n "$I" ]
then
sshpass -p '*******' ssh USER@$I <<EOF
cd
. ./DB.env
sqlplus -S / as sysdba <<SQL
SET SERVEROUTPUT ON
SET ECHO OFF
SET FEEDBACK OFF
SET TIMING OFF
spool /tmp/${HOSTNAME}_check_dblink.out
declare
l_dummy dual.dummy%type;
begin
for r in (select db_link from all_db_links) loop
begin
execute immediate 'select dummy from dual@' || r.db_link into l_dummy;
dbms_output.put_line('Link ' || r.db_link || ' is OK.');
rollback work;
execute immediate 'alter session close database link ' || r.db_link;
exception
when others then
dbms_output.put_line('Link ' || r.db_link || ' is not OK: ' || sqlerrm);
end;
end loop;
end;
/
SQL
EOF
fi
done