I write a script to check db_link'ov. the script works, but if the execution of an anonymous sql block takes some time, the script, without waiting for the sql block to execute, goes to the next server. Even if server 1 it just finishes execution without waiting for the end of the sql block operation.

#!/bin/bash # FILE=`cat /home/oracle/Scripts/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 

I tried to execute the script through the file,

  exit | sqlplus / as sysdba @script.sql 

works the same way, without waiting for execution. Tell me how it can be done so that the script continues to work only after the sql code is executed.

  • Do you really have a heredoc SQL and EOF ending at the beginning of the line? If so, remove everything in front of them. - 0xdb pm

0