Sponsored Content
Top Forums Shell Programming and Scripting loop picks up password for 2 entry...how to avoid that ? Post 302540423 by gary_w on Wednesday 20th of July 2011 02:31:36 PM
Old 07-20-2011
Here it is as a coprocess

I can't test this, but I would be interested in seeing if you like this way with a coprocess better. It is definitely more efficient than starting/closing SQL/Plus for every row in the sidlist file. Try running it with the "time" command and see if it is faster than how you were going to do it before. I have a coprocess example somewhere that I will post that also shows how to retrieve query results into shell variables. I think it would be good info to put out there. Coprocess example: https://www.unix.com/shell-programmin...#post302540429
Code:
#!/bin/ksh

###########################
#check for the oratab file. to get db name and info
###########################
ORATAB=/etc/oratab
LOGFILE=test_output.txt  # Set the logfile in one place so if it changes you have only one place to edit.
output=""                # Output from SQL/Plus goes here.

#
# set ORACLE SID and export path to use as client
#
ORACLE_SID=becsdev
ORAENV_ASK=NO
. oraenv

# Start SQL/Plus as a co-process.
sqlplus -S -NOLOG |&     ## Suppress normal headings and don't logon.

##  Exit SQL/Plus if any of the following signals are received:
##  0=normal exit, 2=interrupt, 3=quit, 9=kill, 15=termination
trap 'print -p "exit"' 0 2 3 9 15

# loop to get sid info
while IFS=',' read ORACLE_SID pass
do
   print '###################################################################################' >> $LOGFILE
   print "ORACLE SID IS SET TO $ORACLE_SID" >> $LOGFILE

   ##  This should have some error handling but for example purposes I assume it will work as expected.
   ##  Usually this is a bad assumption!
   print -p "connect system/${pass}@${ORACLE_SID}"  ## Send the connect command to the coprocess.
   print -p "@test.sql"
   print -p "DONE"
   while read -p output
   do
      if [[ $output == "DONE" ]]; then
        print "DONE" >> $LOGFILE
        break
      else
        # Throw all output into the logfile.
        print $output >> $LOGFILE
      fi
   done
   print '#####################################################################################' >> $LOGFILE
done < /home/sidlist

#  Close SQL/Plus.
print -p "exit"

exit 0


Last edited by gary_w; 07-20-2011 at 03:49 PM..
 

10 More Discussions You Might Find Interesting

1. Programming

/etc/shadow update password entry! ( getspent? )

Hi i just whant to update an password entry in /etc/shadow. But dosen't get it to work. Something is wrong! in this code. What i try do do is if user kalle exist in shadow. I whant it to update it's password for just that entry. #include <stdio.h> #include <errno.h> #include <stdlib.h>... (2 Replies)
Discussion started by: nighter
2 Replies

2. Shell Programming and Scripting

in ftp how to avoid username/password

hi all i am very new to unix. we had the below scenior test.bat file which contains ftp -s:logfiles.scr servername logfiles.scr contains username password cd path get file bye We had n number of batch(.bat files). which is having the same kind of scr file pointing... (10 Replies)
Discussion started by: nh1
10 Replies

3. Shell Programming and Scripting

How to avoid multiple while loop?

Hi, How can I avoid multiple 'cat while read ....? in my script. In my script, I am taking the inputs from the temp text file and doing the ( cat while read input do ... ... done ) task and deleting later. I know it'll raise the perfomance issue. How to avoid this? (2 Replies)
Discussion started by: sharif
2 Replies

4. Shell Programming and Scripting

automating username / password entry

I have a database that contains a list of server names, and the password for the root user on several servers (100+). I need to verify the passwords for each of the servers in an automated fashion because the database continues to grow. All of the users that I'm going to test are ROOT. I can't... (1 Reply)
Discussion started by: jbeck22
1 Replies

5. UNIX for Dummies Questions & Answers

Command to delay password entry - putty connection manager

Hi all, putty connection manager is great but when attempting to sudo or ssh to another box via the post login commands it is subject to issues due to network latency (what happens is that pcm enters the password before the unix box is ready to receive it). Is there any clever way I can make... (1 Reply)
Discussion started by: skinnygav
1 Replies

6. UNIX for Dummies Questions & Answers

grep for password file entry

How would I grep for password file entry without using grep 'username' /etc/passwd? perhaps with who? I want to create alias that will find the password file entry regardless of the user who is using it. I am trying to get the same exact line from the file entry like: Name : Password : UserID... (7 Replies)
Discussion started by: alis
7 Replies

7. UNIX Desktop Questions & Answers

How to grep for password file entry

How would I grep for password file entry without using grep 'username' /etc/passwd? perhaps with who? I want to create alias that will find the password file entry regardless of the user who is using it. Thanks (4 Replies)
Discussion started by: alis
4 Replies

8. Shell Programming and Scripting

Automatic su password entry script

Before I start, two things. 1) Yes I know it's bad practice and obomination to all things holy, but I'm not a sys admin at JP Morgan, I'm a hobbyist tooling about in a VM, in my pants, at home. 2) If you are just going to flame for even considering hardcoding a root password, thanks, I get... (2 Replies)
Discussion started by: 3therk1ll
2 Replies

9. Shell Programming and Scripting

Avoid multiple emails being sent - Counter, Loop?

Hello, I have currently coded a bash script below in which it does the following: # Archives compressed file from another location. Basically it moves *.gz files to another location. The script also sends an email whenever a new compressed file is placed. This is the issue that i... (5 Replies)
Discussion started by: Wizard_1979
5 Replies

10. Solaris

Set password in bash script without manual entry-Solaris 10

Hi I have a root script which is setting up user and his dirs and so on. After I create user and set up all the necessary I have to manually set user password. I try all possible ways what google find me and nothing works for me. If maybe one of you have a solution for my problem it will be... (1 Reply)
Discussion started by: Jaffakeks
1 Replies
print(1)							   User Commands							  print(1)

NAME
print - shell built-in function to output characters to the screen or window SYNOPSIS
ksh print [ -Rnprsu [n]] [arg...] DESCRIPTION
ksh The shell output mechanism. With no flags or with flag - or -, the arguments are printed on standard output as described by echo(1). OPTIONS
The following options are supported: -n suppresses new-line from being added to the output. -R -r (raw mode) ignore the escape conventions of echo. The -R option will print all subsequent arguments and options other than -n. -p causes the arguments to be written onto the pipe of the process spawned with |& instead of standard output. -s causes the arguments to be written onto the history file instead of standard output. -u [ n ] flag can be used to specify a one digit file descriptor unit number n on which the output will be placed. The default is 1. EXIT STATUS
The following exit values are returned: 0 Successful operation. >0 Output file is not open for writing. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWcsu | +-----------------------------+-----------------------------+ SEE ALSO
echo(1), ksh(1), attributes(5) SunOS 5.10 15 Apr 1994 print(1)
All times are GMT -4. The time now is 09:38 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy