Help with script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with script
# 1  
Old 12-08-2004
Help with script

All,

I am trying to connect to sqlplus from my unix shell, i am able to connect but is there a way that i can get the status of whether the database is running ? That is i want to store the output code from the sqlplus command into a variable and write the rest of my code based on that.

Can anyone help ???

Heres what i am trying to do

#!/bin/ksh
dbstatus=`sqlplus -s ptx_msgpoller/ptx01_glovia@prdm.world << !
exit !`

echo $dbstatus

The output of this script returns a large chunk of data, i want to grep for the string Connected in this output but i am not able to.

Heres the output i get.

SQL*Plus: Release 9.2.0.1.0 - Production on Wed Dec 8 12:11:05 2004 Copyright (c
) 1982, 2002, Oracle Corporation. All rights reserved. Connected to: Oracle8i En
terprise Edition Release 8.1.7.4.0 - Production With the Partitioning option JSe
rver Release 8.1.7.4.0 - Production SQL> Disconnected from Oracle8i Enterprise E
dition Release 8.1.7.4.0 - Production With the Partitioning option JServer Relea
se 8.1.7.4.0 - Production

the grep command does not work on this output, how is it done ?

Please help


Thanks in Advance
Swaraj





#cat output
# 2  
Old 12-08-2004
Did u try .... ?


echo $dbstatus | grep "str"



Is this u want ????
# 3  
Old 12-08-2004
Hi Bhargav

I tried that it gives me the same output, but not the String value.


Swaraj
# 4  
Old 12-08-2004
Now ,
i got what u are looking for.

Can u redirect yr sql o/p to a file instead of a variable.
# 5  
Old 12-08-2004
do some thing like this :


if the o/p is not writing new line char at the end , you add new line at the end ;

But 'echo' adds that ......


Try some thing like this, though 'echo' adds one new line


echo $dbstatus
echo "$dbstatus\n" | grep "Disconnected"
# 6  
Old 12-18-2004
sqlplus will run the script file using @filename not just the filename.

See:
Code:
#!/bin/sh

A=`sqlplus -s /nolog @test.sql`

echo $A

test.sql should contain something like.
Code:
connect scott/tiger 
set heading off
select 55 from dual;
exit

This example should simply return "55".

If your script returns many rows (say more than 20 rows), I would not load it in to a variable first, just grep from the sqlplus output.

For your actuall scenario:
Code:
#!/bin/sh
sqlplus -s /nolog @mywrapper.sql | grep string

where mywrapper.sql looks like this:
Code:
connect scott/tiger
set heading off pages 0
@ptx_msgpoller/ptx01_glovia@prdm.world
exit


Last edited by hali; 12-18-2004 at 08:59 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

5 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to block first bash script until second bash script script launches web server/site?

I'm new to utilities like socat and netcat and I'm not clear if they will do what I need. I have a "compileDeployStartWebServer.sh" script and a "StartBrowser.sh" script that are started by emacs/elisp at the same time in two different processes. I'm using Cygwin bash on Windows 10. My... (3 Replies)
Discussion started by: siegfried
3 Replies

2. Shell Programming and Scripting

Shell script works fine as a standalone script but not as part of a bigger script

Hello all, I am facing a weird issue while executing a code below - #!/bin/bash cd /wload/baot/home/baotasa0/sandboxes_finance/ext_ukba_bde/pset sh UKBA_publish.sh UKBA 28082015 3 if then echo "Param file conversion for all the areas are completed, please check in your home directory"... (2 Replies)
Discussion started by: ektubbe
2 Replies

3. UNIX for Dummies Questions & Answers

Calling a script from master script to get value from called script

I am trying to call a script(callingscript.sh) from a master script(masterscript.sh) to get string type value from calling script to master script. I have used scripts mentioned below. #masterscript.sh ./callingscript.sh echo $fileExist #callingscript.sh echo "The script is called"... (2 Replies)
Discussion started by: Raj Roy
2 Replies

4. Shell Programming and Scripting

Script will keep checking running status of another script and also restart called script at night

I am using blow script :-- #!/bin/bash FIND=$(ps -elf | grep "snmp_trap.sh" | grep -v grep) #check snmp_trap.sh is running or not if then # echo "process found" exit 0; else echo "process not found" exec /home/Ketan_r /snmp_trap.sh 2>&1 & disown -h ... (1 Reply)
Discussion started by: ketanraut
1 Replies

5. Shell Programming and Scripting

create a shell script that calls another script and and an awk script

Hi guys I have a shell script that executes sql statemets and sends the output to a file.the script takes in parameters executes sql and sends the result to an output file. #!/bin/sh echo " $2 $3 $4 $5 $6 $7 isql -w400 -U$2 -S$5 -P$3 << xxx use $4 go print"**Changes to the table... (0 Replies)
Discussion started by: magikminox
0 Replies
Login or Register to Ask a Question