parsing output from SQL querry


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting parsing output from SQL querry
# 1  
Old 10-22-2007
parsing output from SQL querry

Hi all

I have this output in a variable called ...yes $OUTPUT :-) original...huh
these are tablespaces in an Oracle db
how do I get this into another variable in two columns
so I can do a check on the numbers (space left)

SYSTEM 290; USERS 19; UNDOTBS1 1863; DATA 5982; SYSTEM 290; USERS 19; UNDOTBS1 1863; DATA 5982;

I hope you guys can help ..

Thanks Tom
# 2  
Old 10-22-2007
Code:
s="SYSTEM 290; USERS 19; UNDOTBS1 1863; DATA 5982; SYSTEM 290; USERS 19; UNDOTBS1 1863; DATA 5982;"
echo "$s" | awk  'BEGIN{FS=";";OFS="\n"}{$1=$1;print}' | while read col1 col2; do....done


Last edited by ghostdog74; 10-22-2007 at 08:56 PM..
# 3  
Old 10-22-2007
I´m not really sure what your string is doing and I cant get i running
could you please have a look at the script..
Tom

#!/bin/ksh


ORACLE_HOME=/pack/oracle/product/10.2.0
export ORACLE_HOME

ORACLE_SID=INAPI2
export ORACLE_SID

ORACLE_BASE=/pack/oracle
export ORACLE_BASE

OUTPUT=`sqlplus -s '/ as sysdba' <<-EOF
set heading off feedback off serveroutput on trimout on pagesize 2
select tablespace_name,trunc(sum(bytes)/1024/1024)||';' MB_free from dba_free_sp
ace group by tablespace_name;
/
EOF`

echo "$OUTPUT" | awk 'BEGIN{FS=";";OFS="\n"} { $1=$1;print}' | while read col1 col2; do echo col1

#for i in $res
#do echo $res
#echo $i |tr -d ' '| awk '{ FS = " " ; print $1}'
#| awk '{ FS = " " ; print $1}'
#echo $i
#echo $OUTPUT | while read output;
#do
#TABLESPACE=`echo $OUTPUT | grep ';'`
done
# 4  
Old 10-22-2007
Why don't you tell us what exactly you want to check?
# 5  
Old 10-23-2007
Quote:
Originally Posted by ludvig
I´m not really sure what your string is doing and I cant get i running
could you please have a look at the script..
Tom

#!/bin/ksh


ORACLE_HOME=/pack/oracle/product/10.2.0
export ORACLE_HOME

ORACLE_SID=INAPI2
export ORACLE_SID

ORACLE_BASE=/pack/oracle
export ORACLE_BASE

OUTPUT=`sqlplus -s '/ as sysdba' <<-EOF
set heading off feedback off serveroutput on trimout on pagesize 2
select tablespace_name,trunc(sum(bytes)/1024/1024)||';' MB_free from dba_free_sp
ace group by tablespace_name;
/
EOF`

echo "$OUTPUT" | awk 'BEGIN{FS=";";OFS="\n"} { $1=$1;print}' | while read col1 col2; do echo col1

#for i in $res
#do echo $res
#echo $i |tr -d ' '| awk '{ FS = " " ; print $1}'
#| awk '{ FS = " " ; print $1}'
#echo $i
#echo $OUTPUT | while read output;
#do
#TABLESPACE=`echo $OUTPUT | grep ';'`
done

do u want to print as follows,
table space SYSTEM has 290 MB space left.
table space USERS has 19 MB space left.
table space UNDOTBS1 has 1863 MB space left.
table space DATA has 5982 MB space left.
table space SYSTEM has 290 MB space left.
table space USERS has 19 MB space left.
table space UNDOTBS1 has 1863 MB space left.
table space DATA has 5982 MB space left.
# 6  
Old 10-23-2007
hi
thats excatly what i want,
but piped to a file if there is less than 50 MB freespace

Br Tom
# 7  
Old 10-23-2007
Quote:
Originally Posted by ludvig
hi
thats excatly what i want,
but piped to a file if there is less than 50 MB freespace
[...]

Then just change the query:
Code:
select tablespace_name,trunc(sum(bytes)/1024/1024)||';' MB_free
from dba_free_space
group by tablespace_name
having trunc(sum(bytes)/1024/1024)<50;

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Storing multiple sql queries output into variable by running sql command only once

Hi All, I want to run multiple sql queries and store the data in variable but i want to use sql command only once. Is there a way without running sql command twice and storing.Please advise. Eg : Select 'Query 1 output' from dual; Select 'Query 2 output' from dual; I want to... (3 Replies)
Discussion started by: Rokkesh
3 Replies

2. Shell Programming and Scripting

Parsing nsupdate's output

Anybody that's ever used nsupdate knows that it's error management is not very good. I have a wrapper script that when it's got all the information it needs launches the nsupdate command. This is my attempt at parsing the output to help support users quickly know if the command succeded or... (7 Replies)
Discussion started by: maverick72
7 Replies

3. Shell Programming and Scripting

How to execute a sql querry from shell script?

hello forum , I am new to shell scripting. as part of my assignment i have to execute a sql querry from the shell script. please help me. example. sql queerry:db2 "select emp_id from tsble emp". i have to execute the above querry from the script. advance thanks to forum Siva ranganath (1 Reply)
Discussion started by: workforsiva
1 Replies

4. Shell Programming and Scripting

Awk script to run a sql and print the output to an output file

Hi All, I have around 900 Select Sql's which I would like to run in an awk script and print the output of those sql's in an txt file. Can you anyone pls let me know how do I do it and execute the awk script? Thanks. (4 Replies)
Discussion started by: adept
4 Replies

5. Shell Programming and Scripting

Parsing Output of a Variable

i have a log file that contains something similar to this: one two three four five six seven eight nine ten eleven twelve thirteen fourteen one two three four five six seven eight nine ten eleven twelve thirteen fourteen one two three four five six seven eight nine ten eleven twelve... (3 Replies)
Discussion started by: SkySmart
3 Replies

6. Shell Programming and Scripting

parsing output

Can somebody provide a solution to parse the following; cat /tmp/xxx Name: QUE_REQU (o.mtaseast-o.dmart) (MTPost queue) Number of messages: 66446 (Age 686 min; Size 214 mb) Backlog (messages): 0 (Age 0 min) Name: QUE_REQU... (6 Replies)
Discussion started by: BeefStu
6 Replies

7. Shell Programming and Scripting

Help in executing the following db2 sql querry in unix

Hi All, Please help me out in executing the following db2 querry in unix db2 "select AP_RQ_ACQ_INST_ID || ',' || txn_classifier || ',' || AP_RS_RESP_CD || ',' || (count(*) AS COUNT1) || ',' || (SUM(AP_RQ_TXN_AMT) AS TOTAL_AMT) from TXN_RECORD where CREATE_TS > '2010-11-22 11:00:00.008645' ... (1 Reply)
Discussion started by: dudd9
1 Replies

8. Shell Programming and Scripting

Parsing output

I need to parse the following out put and determine if the USB is a DISK and whether or not it's External. If an HBA line contains "USB" then does the next line contain "DISK" and "External". 0:0,31,0: HBA : (aacraid,1) AAC SCSI 0,0,0: DISK : Adaptec ASR4800SAS Volu0001 ... (6 Replies)
Discussion started by: lochraven
6 Replies

9. Shell Programming and Scripting

parsing output

I have a file that contains the output of the ls -iR command, something like this: ./results: 2504641011 result_1410 2500957642 result_525 2504641012 result_1425 2500957643 result_540 ./tests/1: 2500788755 1 2500788743 1000 ./tests/2: 2500788759 3 2500788758 999 ... (6 Replies)
Discussion started by: looza
6 Replies

10. Shell Programming and Scripting

text parsing querry

$ A=/t1/bin/f410pdb oIFS=$IFS IFS=/ $ set -- $A $ IFS=$oIFS $ echo $2 t1 $ echo $3 bin $ echo $4 f410pdb can any one please explain me what is done with IFS and how it is working internally ...i am interested to know in depth (2 Replies)
Discussion started by: mobydick
2 Replies
Login or Register to Ask a Question