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 > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Problem In Shell Script satyakide Shell Programming and Scripting 11 09-24-2007 10:00 AM
Help! Problem with Shell Script. pektl Shell Programming and Scripting 7 05-29-2006 05:08 AM
Problem with SU or SSH in shell script sravanp UNIX for Dummies Questions & Answers 2 01-24-2006 12:00 PM
Shell Script problem bnohifi Shell Programming and Scripting 1 07-07-2005 02:02 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 01-10-2007
shashi_kiran_v shashi_kiran_v is offline
Registered User
  
 

Join Date: Jun 2005
Posts: 40
Shell script problem

Hi,

I have a shell script in which I am calling a function from a different shell script. This functions executes the SQL and the results are stored in a log file.

If the result of the SQL is "no rows selected" then I need to exit the main shell script. My shell script is executing fine if the records are found. But I am unable to stop or exit the shell script if there are no records found.

I tried using the following step.. but it is not working.

echo $SQL_REPORT | grep 'no' >> /dev/null
if [ $? = 0 ]
then
echo "== Found" >> $LOGFILE_SCRIPT
else
echo "== Not Found" >> $LOGFILE_SCRIPT
fi

I am able to find it if I 'm using the following code.

VAR=`grep 'no' $SQL_REPORT | sed -e "s/ //g;s/[ ]*$//" | cut -c1-14`
if [ $VAR = 'norowsselected' ]
then
exit
fi

But u can't always expect the result as "no rows selected".

Hope I have made it clear.

Thanks
Shash
  #2 (permalink)  
Old 01-10-2007
Krrishv Krrishv is offline
Registered User
  
 

Join Date: Dec 2006
Location: CA,United States
Posts: 186
echo $SQL_REPORT | grep 'no' >> /dev/null
if [ $? -eq 0 ]
then
echo "== Found" >> $LOGFILE_SCRIPT
else
echo "== Not Found" >> $LOGFILE_SCRIPT
exit 0
fi

try this
  #3 (permalink)  
Old 01-10-2007
ranj@chn ranj@chn is offline Forum Advisor  
Playing with Ubuntu Now!
  
 

Join Date: Oct 2005
Location: Chennai
Posts: 365
this one?

Code:
if grep -is 'no rows selected' $logfile >/dev/null
then
echo "pattern found"
else
echo "not found"
fi

Last edited by ranj@chn; 01-10-2007 at 11:15 AM.. Reason: typo
  #4 (permalink)  
Old 01-10-2007
shashi_kiran_v shashi_kiran_v is offline
Registered User
  
 

Join Date: Jun 2005
Posts: 40
Thanks a lot ranj!! It worked.
  #5 (permalink)  
Old 01-10-2007
shashi_kiran_v shashi_kiran_v is offline
Registered User
  
 

Join Date: Jun 2005
Posts: 40
But is there any way I can totally come out of the main script.
This exit is only coming out of the function and the loop in which the main shell script was calling the function.

I need to stop the main script at this point of time.
  #6 (permalink)  
Old 01-10-2007
shashi_kiran_v shashi_kiran_v is offline
Registered User
  
 

Join Date: Jun 2005
Posts: 40
Did a work around by creating a flag file and then checking for its existence in the main script to exit completely.
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 04:26 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