shell script cant recognize if else compare


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting shell script cant recognize if else compare
# 1  
Old 12-05-2005
shell script cant recognize if else compare

hi

I face the problem the if else statement dint return correct result for me
my script as below:

#!/bin/ksh
sqlplus -s /nolog <<EOF
connect databaseuser/password
column num new_value num format 9999
set head off
select count(*) num from table1;
exit num
EOF

if [ $? -gt 10 ]; then
echo "$?"
else
echo "stop"
fi

-----
How I know $? is integer? Is it because both is not integer
so cant go the compare??

Any one please help ,


Thanks and regards,
Jase
# 2  
Old 12-05-2005
what exactly your if is returning?
# 3  
Old 12-05-2005
What are you actually trying to compare with 10? If it is the output of the query i.e. (count(*) ) that you are trying to compare with 10 then you can use the following code.

#!/bin/ksh
RESULT=`sqlplus -s /nolog <<EOF
connect databaseuser/password
set head off
select count(*) from table1;
EOF`

if [ $RESULT -gt 10 ]; then
echo $RESULT
else
echo "stop"
fi
# 4  
Old 12-05-2005
Thanks for your reply
Yes, I need to compare the result from the query, if the count(*) > 10 then some action I need to take...but it seem like the result is not integer..so it cant be compare with number.. got any way to convert it to integer..


sowjanya.addala
I had try this before but the RESULT cant go to proceed the sql statement inside. The value of the RESULT is just capture the SQL statement not the output query.
any way appreciate your help.

regards,
Jase

Last edited by jaseloh; 12-05-2005 at 08:46 PM..
# 5  
Old 12-06-2005
look at this

#!/bin/ksh
RESULT=`sqlplus -s /nolog <<EOF
connect databaseuser/password
set head off
spool log;
select count(*) from table1;
EOF`
RESULT=`head log.lst`
if [ $RESULT -gt 10 ]; then
echo $RESULT
else
echo "stop"
fi
# 6  
Old 12-06-2005
Things are being unnecessarily complicated here. Try this:
Code:
#!/usr/bin/ksh

count=$(sqlplus -s /nolog << !|egrep -v "^$|Connected"
conn user/passwd;
set head off feed off;
select count(*) from some_table;
quit;
!)
echo $count

Please remember that any '$' signs in the query are to be escaped with '\'.
# 7  
Old 12-06-2005
Problem solve

Hi all,

Thanks for your help. my problem solve.
I jst change the #!/bin/ksh to #!/bin/sh, then it can work properly.
But I dont know why....


regards,
Jase
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to recognize the Shell?

Hello All I am working on Red Hat Enterprise Linux Server release 5.1 when I logged on to the shell and then write echo $SHELL it shows me the result /bin/bash and when I write csh, the prompt changes and I feel that I am now working upon C shell but when I do echo $SHELL it shows me the... (9 Replies)
Discussion started by: adisky123
9 Replies

2. Shell Programming and Scripting

How does a shell script recognize the end of a line?

Hi friends , I want to know how does a shell script recognize the end of a line? . i have hunddres of proccedure to test where i want to ingnore the comments which starts with "--" .. it can start from the middle of the lines also. for example:: select * from table1; -- getting... (5 Replies)
Discussion started by: neelmani
5 Replies

3. Shell Programming and Scripting

Compare two files using shell script

Hi i want to compare two files and i need the o/p of only difference here the files file1 achilles aedxbepo aedxbwdm01 aedxbwdm02 albedo amarice ambrister anakin anton argon artephius asgard avatar aymara (10 Replies)
Discussion started by: venikathir
10 Replies

4. Shell Programming and Scripting

Shell script to compare two files

I have two files; file A and file B. I need all the entries of file A to be compared with file B line by line. If the entry exists on file B, then save those on file C; if no then save it on file D Note :- all the columns of the lines of file A need to be compared, except the last two columns... (8 Replies)
Discussion started by: ajiwww
8 Replies

5. Shell Programming and Scripting

Shell Script to Compare Two Files

I have a directory with about 6 files that we receive regularly. these 6 files contain information for 3 different units, 2 for each unit. files related to a specific unit are named similarly with a change in number at the end of the file. the numbers should be sequential. for each grouping of... (3 Replies)
Discussion started by: scriptman237
3 Replies

6. Shell Programming and Scripting

how to compare two lines using shell script?

how to compare two lines using shell script? (1 Reply)
Discussion started by: suman_dba1
1 Replies

7. Shell Programming and Scripting

String compare in shell script

Iam trying to compare the string in if else... but some how its not working following is the code On executing the above one its giving a error message ': bad number' in the above parameter l & k are numbers and dbfiles and patchefiles are array If i do echo ift working fine ... (2 Replies)
Discussion started by: kiranlalka
2 Replies

8. UNIX and Linux Applications

How to compare two files using shell script

hi experts please help me to compare two files which are in different directory file1<file will be master file> (/home/rev/mas.txt} ex x1 x2 file2 <will be in different folder> (/home/rev/per/.....) ex x3 x4 the filesinside per folder i need to compare with master file... (1 Reply)
Discussion started by: revenna
1 Replies

9. Shell Programming and Scripting

compare two tables using shell script

Hi, I want to compare two tables fieldwise using shell script. Can anyone help me regarding the same. The approach which i tried is to first move the two tables in simple txt file where each field is now seperated by space. But i can't retrive each field with "space" as a seperator b'coz there... (1 Reply)
Discussion started by: dtidke
1 Replies

10. Shell Programming and Scripting

How to compare the dates in shell script

Hi How to compare created or modified date of two files help needed thanks Vajiramani :) (9 Replies)
Discussion started by: vaji
9 Replies
Login or Register to Ask a Question