Sponsored Content
Top Forums UNIX for Beginners Questions & Answers Control not returning to UNIX when sqlplus is executed in while loop of shell script Post 303045804 by preetham30 on Monday 13th of April 2020 09:01:15 PM
Old 04-13-2020
Control not returning to UNIX when sqlplus is executed in while loop of shell script

Hi All,

I have observed some of the scripts gets stuck because sqlplus session is not completing it's session. This behavior is intermittent. I will give one of the scenario. Below is the code which executes one sql query.



Code:
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 
}



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.

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.

Last edited by preetham30; 04-15-2020 at 10:23 AM..
 

10 More Discussions You Might Find Interesting

1. Programming

Returning Strings from C program to Unix shell script

Hi, Iam calling a C program from a Unix shell script. The (C) program reads encrypted username/password from a text file , decrypts and returns the decrypted string. Is there any way i can return the decrypted string to Unix shell program. My shell script uses the output of the program to... (11 Replies)
Discussion started by: satguyz
11 Replies

2. Shell Programming and Scripting

Unix shell script couldn't be executed. Pls help!

I have wrriten a script to call sql script to do some work in database. However, the script couldn't be executed. The only information was: ksh: ./updt_attrib.ksh cannot execute. Please help me to identify where the problem is. I post script here for your reference. Thanks a lot. #!/bin/ksh ... (8 Replies)
Discussion started by: duke0001
8 Replies

3. Programming

Returning Strings from C program to Unix shell script

Hi, I'm having a requirement where I need to call a C program from a shell script and return the value from the C program to shell script. I refered a thread in this forum. But using that command in the code, it is throwing an error clear_text_password=$(get_password) Error: bash:... (24 Replies)
Discussion started by: venkatesh_sasi
24 Replies

4. Shell Programming and Scripting

returning un executed string to shell prompt

Hi all, i'm pritty new to chell scripting I'm trying to find a way to return a value to shell without it executing. is there a special character that will encase a sting including the command to a shell without executing, so waiting for the user to press enter. say i wanted to return a value... (3 Replies)
Discussion started by: jvan
3 Replies

5. Shell Programming and Scripting

(Urgent):Creating flat file using sql script and sqlplus from UNIX Shell Script

Hi, I need help urgently for following issue. Pls help me to resolve this issue. I am calling sql script file(file1.sql) from UNIX Shell Script(script1.ksh) using sql plus and trying to create flat file that contains all records returned from SQL query in SQL script(file1.sql) I given... (6 Replies)
Discussion started by: praka
6 Replies

6. UNIX for Dummies Questions & Answers

calling a unix shell script from sqlplus

I want to execute a shell script from sqlplus prompt and get its output back to sqlplus. Is this possible? if yes just give me an example for doing that. (2 Replies)
Discussion started by: boopathyvasagam
2 Replies

7. UNIX for Dummies Questions & Answers

How to send keyboard inputs toa UNIX command executed from a shell script?

I have a unix command that prompts for 'y'. How do I run this from my shell script? (4 Replies)
Discussion started by: Sree10
4 Replies

8. Shell Programming and Scripting

Control from UNIX script is not returning to the Parent program

Hi All, My program flow is as below Windows batch -- > Cygwin batch --> zsh script There are multiple Cygwin batch scripts that are called from Windows batch file . But when i am executing the first cygwin batch script the control goes to the zsh file and executes and stoping from... (1 Reply)
Discussion started by: Hypesslearner
1 Replies

9. Shell Programming and Scripting

Control not returning from Sqlplus to calling UNIX shell script.

Hello All, I have a UNIX script which will prepare anonymous oracle pl/sql block in a temporary file in run time and passes this file to sqlplus as given below. cat > $v_Input_File 2>>$v_Log << EOF BEGIN EXECUTE IMMEDIATE 'ALTER SESSION FORCE PARALLEL DML PARALLEL 16'; EXECUTE... (1 Reply)
Discussion started by: vikas_trl
1 Replies

10. Shell Programming and Scripting

Control not returning from Sqlplus to calling UNIX shell script.

Hello All, I have exactly same issue @vikas_trl had in following link: https://www.unix.com/shell-programming-and-scripting/259854-control-not-returning-sqlplus-calling-unix-shell-script.html I wonder if he or somebody else could find the issue's cause or the solution. Any help would... (4 Replies)
Discussion started by: RicardoQ
4 Replies
SCRIPT(1)							   User Commands							 SCRIPT(1)

NAME
script - make typescript of terminal session SYNOPSIS
script [options] [file] DESCRIPTION
script makes a typescript of everything displayed on your terminal. It is useful for students who need a hardcopy record of an interactive session as proof of an assignment, as the typescript file can be printed out later with lpr(1). If the argument file is given, script saves the dialogue in this file. If no filename is given, the dialogue is saved in the file type- script. OPTIONS
-a, --append Append the output to file or to typescript, retaining the prior contents. -c, --command command Run the command rather than an interactive shell. This makes it easy for a script to capture the output of a program that behaves differently when its stdout is not a tty. -e, --return Return the exit code of the child process. Uses the same format as bash termination on signal termination exit code is 128+n. -f, --flush Flush output after each write. This is nice for telecooperation: one person does `mkfifo foo; script -f foo', and another can supervise real-time what is being done using `cat foo'. --force Allow the default output destination, i.e. the typescript file, to be a hard or symbolic link. The command will follow a symbolic link. -q, --quiet Be quiet (do not write start and done messages to standard output). -t[file], --timing[=file] Output timing data to standard error, or to file when given. This data contains two fields, separated by a space. The first field indicates how much time elapsed since the previous output. The second field indicates how many characters were output this time. This information can be used to replay typescripts with realistic typing and output delays. -V, --version Display version information and exit. -h, --help Display help text and exit. NOTES
The script ends when the forked shell exits (a control-D for the Bourne shell (sh(1)), and exit, logout or control-d (if ignoreeof is not set) for the C-shell, csh(1)). Certain interactive commands, such as vi(1), create garbage in the typescript file. script works best with commands that do not manipulate the screen, the results are meant to emulate a hardcopy terminal. It is not recommended to run script in non-interactive shells. The inner shell of script is always interactive, and this could lead to unexpected results. If you use script in the shell initialization file, you have to avoid entering an infinite loop. You can use for example the .profile file, which is read by login shells only: if test -t 0 ; then script exit fi You should also avoid use of script in command pipes, as script can read more input than you would expect. ENVIRONMENT
The following environment variable is utilized by script: SHELL If the variable SHELL exists, the shell forked by script will be that shell. If SHELL is not set, the Bourne shell is assumed. (Most shells set this variable automatically). SEE ALSO
csh(1) (for the history mechanism), scriptreplay(1) HISTORY
The script command appeared in 3.0BSD. BUGS
script places everything in the log file, including linefeeds and backspaces. This is not what the naive user expects. script is primarily designed for interactive terminal sessions. When stdin is not a terminal (for example: echo foo | script), then the session can hang, because the interactive shell within the script session misses EOF and script has no clue when to close the session. See the NOTES section for more information. AVAILABILITY
The script command is part of the util-linux package and is available from Linux Kernel Archive <https://www.kernel.org/pub/linux/utils /util-linux/>. util-linux June 2014 SCRIPT(1)
All times are GMT -4. The time now is 08:33 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy