Control not returning to UNIX when sqlplus is executed in while loop of shell script [message #679922] |
Mon, 13 April 2020 23:05 |
|
preetham30
Messages: 6 Registered: April 2020 Location: Toronto
|
Junior Member |
|
|
Hi All,
I have observed some of the shell scripts gets stuck because sqlplus session is not completing its session. This behavior is intermittent. I will give one of the scenario. Below is the code which executes one sql query.
if [[ ${rcloop1} -eq 0 ]]; then
sql_cnt_loop=0
# perform 2nd loop after 1 second to check if Indexing has completed
sleep 1
while : ; do
exec_SQL "SELECT count(*) \
FROM server_states \
WHERE topic = 'WLM_FPFA_INDEXES' \
AND current_state <> new_state \
AND server_name in ('${E_WLM_BATCH_SERVER_NAME_1}', '${E_WLM_BATCH_SERVER_NAME_2}')"
rcloop2=$?
if [[ $rcloop2 -eq 0 ]]; then
sql_cnt_loop=$sql_cnt_loop+1
if [[ ${E_WLM_SQL_RESULT} -eq 0 ]]; then
Log "DJ Indexing has Completed..."
rcloop2=0 # no rows - indexing has completed (not found in server_states table), return RC=0
break # exit from 2nd loop
elif [[ ${E_WLM_SQL_RESULT} -gt 0 ]]; then
sleep 1 # wait 1 sec then loop again
continue # record exists, continue monitoring indexing - loop again
fi
fi
done
rc=$rcloop2
else
rc=$rcloop1
fi
below is the unix session.
pwlm 8297 8290 0 00:16 ? 00:00:03 /bin/ksh -a /opt/XWLMLL02
pwlm 29121 8297 0 00:32 ? 00:00:00 sqlplus -s
The script has run a process internally and above code part is to monitor whether the process is completed. Even though the process is completed, the script has not moved further from this point. Upon checking further, I have seen one active sqlplus session. I suspect that the sqlplus session is from the above code and it is somehow stuck in turn the script has stuck.
Below is the actual function exec_SQL.
exec_SQL()
{
sql_Stmt=$1
sql_Type=`echo $sql_Stmt | awk -F " " '{ printf toupper($1) }'`
E_WLM_SQL_RESULT=`sqlplus -s /@${E_WLM_DB} <<!
set pagesize 0 feedback off verify off heading off echo on
whenever SQLERROR exit SQL.SQLCODE
whenever OSERROR exit 9
$sql_Stmt;
commit;
!`
sql_RC=$?
if [[ $sql_RC -eq 0 ]]; then
str_Result=`echo $E_WLM_SQL_RESULT | grep SP2`
if [[ ${#str_Result} > 0 ]]; then
sql_RC=57 # SQL Error
sql_Code=0
else
export E_WLM_SQL_RESULT
fi
else
sql_Code=$sql_RC # Store SQL.SQLCODE before overwriting
if [[ $sql_RC -eq 9 ]]; then # OSERROR
sql_RC=91
else
case $sql_Type in
INSERT) sql_RC=52 ;;
UPDATE) sql_RC=53 ;;
SELECT) sql_RC=54 ;;
DELETE) sql_RC=56 ;;
*) sql_RC=57 ;;
esac
fi
fi
if [[ $sql_RC -ne 0 ]]; then
Log "Error in executing SQL Statement: $sql_Stmt "
Log "SQL.SQLCODE=$sql_Code"
Log "===================================== ORACLE ERROR DESCRIPTION ====================================="
Log "$E_WLM_SQL_RESULT"
Log "======================================================================================================="
Log "Returning with $sql_RC"
fi
return $sql_RC
}
I have observed this similar issue 3 times till now in the past 7 days. But, it is for different scripts. The logic remains the same.
This script was working fine in our old infrastructure where there was AIX server. We have not at all faced this issue over there.
Anyone, could help me to resolve the issue?
Thanks in Advance.
|
|
|
|
|
|
|
|
|
|
|
|
|
Re: Control not returning to UNIX when sqlplus is executed in while loop of shell script [message #680240 is a reply to message #680016] |
Wed, 29 April 2020 17:11 |
|
preetham30
Messages: 6 Registered: April 2020 Location: Toronto
|
Junior Member |
|
|
Hi Michel,
After I enabled the trace logs, we got this issue yesterday and today. Almost after 2 weeks. In both cases, the trace log stuck at the below place.
(3460657536) [29-APR-2020 07:56:36:908] nsprecv: 00 0A 00 00 05 02 00 00 |........|
(3460657536) [29-APR-2020 07:56:36:908] nsprecv: 01 36 |.6 |
(3460657536) [29-APR-2020 07:56:36:908] nsprecv: normal exit
(3460657536) [29-APR-2020 07:56:36:908] nscon: got NSPTRD packet
(3460657536) [29-APR-2020 07:56:36:908] nscon: recving connect data
(3460657536) [29-APR-2020 07:56:36:908] nsdo: entry
(3460657536) [29-APR-2020 07:56:36:908] nsdo: cid=0, opcode=68, *bl=310, *what=1, uflgs=0x4001, cflgs=0x0
(3460657536) [29-APR-2020 07:56:36:908] nsdo: nsctx: state=2, flg=0x804005, mvd=0
(3460657536) [29-APR-2020 07:56:36:908] nsdo: gtn=10, gtc=10, ptn=10, ptc=8111
(3460657536) [29-APR-2020 07:56:36:908] nsrdr: entry
(3460657536) [29-APR-2020 07:56:36:908] nsrdr: recving a packet
(3460657536) [29-APR-2020 07:56:36:908] nsprecv: entry
(3460657536) [29-APR-2020 07:56:36:908] nsprecv: reading from transport...
(3460657536) [29-APR-2020 07:56:36:908] nttrd: entry
Thanks,
Preetham
|
|
|
|
|
|
|