The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 and shell scripting languages 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 05:18 AM
how to compare text value in shell reply2soumya UNIX for Advanced & Expert Users 2 06-19-2007 01:03 PM
How to recognize that the server is currently unavailable? munna_dude High Level Programming 2 03-10-2007 12:16 AM
How to compare the dates in shell script vaji Shell Programming and Scripting 9 02-28-2007 12:34 AM
Doesn't recognize the mv command zoolz Shell Programming and Scripting 2 11-14-2005 10:20 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 12-05-2005
jaseloh jaseloh is offline
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
  #2 (permalink)  
Old 12-05-2005
Raom Raom is offline
Registered User
  
 

Join Date: Sep 2005
Location: india
Posts: 79
what exactly your if is returning?
  #3 (permalink)  
Old 12-05-2005
sowjanya.addala sowjanya.addala is offline
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
  #4 (permalink)  
Old 12-05-2005
jaseloh jaseloh is offline
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 08:46 PM..
  #5 (permalink)  
Old 12-06-2005
Raom Raom is offline
Registered User
  
 

Join Date: Sep 2005
Location: india
Posts: 79
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 (permalink)  
Old 12-06-2005
blowtorch's Avatar
blowtorch blowtorch is offline Forum Advisor  
Supporter
  
 

Join Date: Dec 2004
Location: Singapore
Posts: 2,350
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 (permalink)  
Old 12-06-2005
jaseloh jaseloh is offline
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
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 09:44 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0