The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Compare two dates using Shell Programming dave_nithis Shell Programming and Scripting 4 01-04-2008 02:18 AM
how to compare text value in shell reply2soumya UNIX for Advanced & Expert Users 2 06-19-2007 10:03 AM
How to recognize that the server is currently unavailable? munna_dude High Level Programming 2 03-09-2007 09:16 PM
How to compare the dates in shell script vaji Shell Programming and Scripting 9 02-27-2007 09:34 PM
Doesn't recognize the mv command zoolz Shell Programming and Scripting 2 11-14-2005 07:20 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 12-05-2005
Registered User
 

Join Date: Dec 2005
Posts: 11
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
Reply With Quote
Forum Sponsor
  #2  
Old 12-05-2005
Registered User
 

Join Date: Sep 2005
Location: india
Posts: 78
what exactly your if is returning?
Reply With Quote
  #3  
Old 12-05-2005
Registered User
 

Join Date: Dec 2005
Posts: 2
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
Reply With Quote
  #4  
Old 12-05-2005
Registered User
 

Join Date: Dec 2005
Posts: 11
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 05:46 PM.
Reply With Quote
  #5  
Old 12-05-2005
Registered User
 

Join Date: Sep 2005
Location: india
Posts: 78
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
Reply With Quote
  #6  
Old 12-05-2005
blowtorch's Avatar
Supporter
 
Join Date: Dec 2004
Location: Singapore
Posts: 2,328
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 '\'.
Reply With Quote
  #7  
Old 12-06-2005
Registered User
 

Join Date: Dec 2005
Posts: 11
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
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 11:59 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0