How to compare to values returned from sql in shell scripting?


 
Thread Tools Search this Thread
# 8  
hey , i have tried somthing different for that but still not working only the else part is being shown in the result.

Code:
#!/bin/bash

val=$(sqlplus -s rte/rted2@rel76d2 <<EOF
set heading off
set feedback off
SELECT MAX(STAT_ID) FROM CVT_STATS;
exit
EOF)
echo $val
nohup ./cvt -f MediationSources.xml &

sleep 60

value=$(sqlplus -s rte/rted2@rel76d2 <<EOF
set heading off
set feedback off
SELECT MAX(STAT_ID) FROM CVT_STATS;
exit
EOF)
echo "\"$val\""
echo "\"$value\""
diff = $((value - val))
echo $diff
if [$diff -gt "0"] ; then
     echo "PASS"
else
     echo "FAIL"
fi


Last edited by Scott; 05-07-2013 at 10:12 AM.. Reason: Code tags - not ICode tags - please
# 9  
First of all I would like to tell you, do not open duplicate thread

Now for the issue that you are facing. I would like to suggest you to set xtrace / verbose and debug script yourself to understand what exactly is happening:
Code:
#!/bin/bash -xv

# 10  
diff is for comparing files, not variables.

And you're still not using spaces in your tests.
Code:
if [$diff -gt "0"]

is wrong.

Please use bash -n before running your script. It will point out the syntax errors.
# 11  
hey i have tried to debug it but i am not able to understand as i am a beginner.
so can u pls help me out
Code:
#!/bin/bash -xv
val=$(sqlplus -s rte/rted2@rel76d2 <<EOF
set heading off
set feedback off
SELECT MAX(STAT_ID) FROM CVT_STATS;
exit
EOF)
sqlplus -s rte/rted2@rel76d2 <<EOF
set heading off
set feedback off
SELECT MAX(STAT_ID) FROM CVT_STATS;
exit
EOF)
./sql.sh: line 13: warning: here-document at line 8 delimited by end-of-file (wanted `EOF')
sqlplus -s rte/rted2@rel76d2 <<EOF
set heading off
set feedback off
SELECT MAX(STAT_ID) FROM CVT_STATS;
exit
EOF
++ sqlplus -s rte/rted2@rel76d2
+ val='
         526'
echo $val
+ echo 526
526
nohup ./cvt -f MediationSources.xml &

sleep 60
+ sleep 60
+ nohup ./cvt -f MediationSources.xml
nohup: appending output to `nohup.out'

value=$(sqlplus -s rte/rted2@rel76d2 <<EOF
set heading off
set feedback off
SELECT MAX(STAT_ID) FROM CVT_STATS;
exit
EOF)
sqlplus -s rte/rted2@rel76d2 <<EOF
set heading off
set feedback off
SELECT MAX(STAT_ID) FROM CVT_STATS;
exit
EOF)
./sql.sh: line 24: warning: here-document at line 19 delimited by end-of-file (wanted `EOF')
sqlplus -s rte/rted2@rel76d2 <<EOF
set heading off
set feedback off
SELECT MAX(STAT_ID) FROM CVT_STATS;
exit
EOF
++ sqlplus -s rte/rted2@rel76d2
+ value='
         527'
echo "\"$val\""
+ echo '"
         526"'
"
         526"
echo "\"$value\""
+ echo '"
         527"'
"
         527"
abc = $((value - val))
+ abc = 1
./sql.sh: line 21: abc: command not found
echo $abc
+ echo

if [[$abc -gt 0]] ;then
     echo "PASS"
else
     echo "FAIL"
fi
+ '[[' -gt '0]]'
./sql.sh: line 23: [[: command not found
+ echo FAIL
FAIL


Last edited by Scott; 05-07-2013 at 10:41 AM.. Reason: Code tags
# 12  
Copy this code as it is and try to run:
Code:
#!/bin/bash

val_1=$( sqlplus -s rte/rted2@rel76d2 << EOF
set heading off
SELECT MAX(STAT_ID) FROM CVT_STATS;
exit
EOF
)
echo "val_1: $val_1"

nohup ./cvt -f MediationSources.xml &
sleep 60

val_2=$( sqlplus -s rte/rted2@rel76d2 << EOF
set heading off
SELECT MAX(STAT_ID) FROM CVT_STATS;
exit
EOF
)
echo "val_2: $val_2"

if [ $val_1 -ne $val_2 ]
then
     echo "PASS"
else
     echo "FAIL"
fi

This User Gave Thanks to Yoda For This Post:
 

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Generate sql statement using shell scripting

Can anyone please assist me? I have attached 2 input files and one output file. I need to generate the sql update statements using the above 2 input files. if inputfile2 has 5 rows, then we should generate 5 update statements because column1 is unique. inputfile1 and inputfile2 may contain more... (10 Replies)
Discussion started by: vinus
10 Replies

2. Shell Programming and Scripting

Shell Scripting question with SQL

hey i have to connect to sql through shell script , then store the value of the query in a variable and then compare it after some time after running a process. i have used this code but it is not working. #!/bin/sh Val = (sqlplus -s rte/rted2@rel76d2 <<! SELECT MAX(STAT_ID) FROM CVT_STATS;... (3 Replies)
Discussion started by: ramsavi
3 Replies

3. Shell Programming and Scripting

Sql issue in shell scripting

HI friends , i am also facing an issue in mysql i ma trying to insert detail in a variable but not got success #!/bin/sh mysql -u<username> -p<password> <dbname> << EOF DEV=`mysql --skip-column-names <dbname> -e "SELECT timestamp from process_record where id = 1"` EOF echo $DEV ERROR... (3 Replies)
Discussion started by: sanjay833i
3 Replies

4. Shell Programming and Scripting

SQL commands in a shell scripting

Hi, I need to write a shell script file that does 1)Connects to DB using SQL plus 2)Do some SQL query like select * from.... 3)Based on the output that I got from the sql query I will have to write a if else loop. Plz let me know how to write the shell scripting for this. Thanks for... (1 Reply)
Discussion started by: villain41
1 Replies

5. Shell Programming and Scripting

Sql & Shell scripting book

Hi, I am looking for some books that have examples of both Oracle SQL and Shell script being used together. For example, to insert 500 rows into a table using a script. I already have books that cover Shell scripting or SQL, but as separate subjects. I am looking for books that have both of... (3 Replies)
Discussion started by: handle123
3 Replies

6. Shell Programming and Scripting

passing values from sql to shell script

Hi guyz, Posting a thread after a long time. I want to pass two variables to unix shell script from sql script. Note: I am calling sql script from unix script. sql script has 2 variables one is the return code for status of program run and second one email flag. I don't know how to capture... (3 Replies)
Discussion started by: sachin.gangadha
3 Replies

7. Shell Programming and Scripting

how towrite sql in shell scripting

hi iam new of scipiting.give me the some Material of regarding sql in scripting. and i have no backup's in 3 severs.how to write script in dirctory. please give me some usefull information cheers Naveen.g (2 Replies)
Discussion started by: naveeng.81
2 Replies

8. UNIX for Dummies Questions & Answers

Aggregate values in a file & compare with sql output

Hi, I have a file containing the following data: junk123junk723itemcode001qty01price10total10junkjunk junk123junk723itemcode002qty02price10total20junkjunk .. .. .. could be 5000+ lines I have an algo and need a code to implement this: 1. Linecount = wc -l (should give 5000) 2. For i... (1 Reply)
Discussion started by: shiroh_1982
1 Replies

9. Shell Programming and Scripting

Shell scripting and SQL

Hi, I have a file that has contents like this: SQL> select * from details; NAME REG -------------------- ---------- Mani 1 Santosh 2 Manju 3 Mukesh 4 SQL> spool off; ... (5 Replies)
Discussion started by: sendhilmani123
5 Replies

10. Shell Programming and Scripting

Sql with shell scripting

Hi, I want to extract data from database table to a flat file using shell scripting. For loading data from file to a table, I had used SQL Loader. How can I do the vice versa using shell scripting. Thanks in advance (3 Replies)
Discussion started by: sendhil
3 Replies

Featured Tech Videos