While loop variable | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


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

While loop variable

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 02-15-2013
netdbaind netdbaind is offline
Registered User
 
Join Date: Aug 2012
Last Activity: 7 August 2014, 2:37 AM EDT
Posts: 45
Thanks: 7
Thanked 0 Times in 0 Posts
While loop variable


Code:
while read -r tabname rem
do
  select count(*) from $tabname" > /dev/null
  RC=$?
  if [[ $RC != 0 ]]
  then
         echo "error on $tabname" >> error.out
         
  fi
done

well in above code i need the echo "error on $tabname" to come in separate o/p file which show the table name whc doesn't pass RC =0. but not getting any o/p in erro.out.Any thing that need to check.??
Sponsored Links
    #2  
Old 02-15-2013
zaxxon's Avatar
zaxxon zaxxon is offline Forum Staff  
code tag tagger
 
Join Date: Sep 2007
Last Activity: 21 August 2014, 8:17 AM EDT
Location: St. Gallen, Switzerland
Posts: 6,225
Thanks: 121
Thanked 450 Times in 410 Posts
Doesn't your shell show any error on this line when executing the script?

Code:
select count(*) from $tabname" > /dev/null

Sponsored Links
    #3  
Old 02-15-2013
netdbaind netdbaind is offline
Registered User
 
Join Date: Aug 2012
Last Activity: 7 August 2014, 2:37 AM EDT
Posts: 45
Thanks: 7
Thanked 0 Times in 0 Posts
hi zaxxon,

actually the code i shown you is not complete ..it has db connection.That part is runnign fine Rc is validating but the Problem is m not getting error.out in separate file.


Code:
echo "error on $tabname" >> error.out

    #4  
Old 02-15-2013
zaxxon's Avatar
zaxxon zaxxon is offline Forum Staff  
code tag tagger
 
Join Date: Sep 2007
Last Activity: 21 August 2014, 8:17 AM EDT
Location: St. Gallen, Switzerland
Posts: 6,225
Thanks: 121
Thanked 450 Times in 410 Posts
Ok
The problem will most probably be, that the DB client you are using, will just show a RC of 0 all the time, no matter if the SQL statement issued was successful or not.
You got the same issue, if you do something with a ftp client or any other client, that works fine in terms of itself, no matter what errors you get "inside" the client. There is usually issued a 0 back to the shell as the client says "Hey man, I am fine, not my fault the commands you issued didn't work because of <insertsomethingthatwentwrong>".

Can simply check this if you add a echo $RC after defining $RC while issuing an intentionally failing SQL statement in the line above.
I am not sure if there is any kind of option for your DB client to pass any other RC through to the shell. Could check it's documentation maybe; or grep for a pattern that shows the success/fail of the operation.

Update:
For DB2 I found that the client returns appropriate RCs:
http://publib.boulder.ibm.com/infoce...e/r0010411.htm
Just as an example that some clients do that.

Last edited by zaxxon; 02-15-2013 at 08:56 AM.. Reason: added info
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Array Variable being Assigned Values in Loop, But Gone when Loop Completes??? mrm5102 Shell Programming and Scripting 5 10-19-2012 10:00 AM
Loop and variable not exactly variable: what's wrong bobylapointe UNIX for Dummies Questions & Answers 4 06-30-2012 07:40 AM
printing variable with variable suffix through loop oly_r Shell Programming and Scripting 4 06-26-2012 02:00 PM
[SHELL: /bin/sh] For loop using variable variable names Vryali Shell Programming and Scripting 2 06-06-2012 10:47 AM
how to get the variable in while loop outside of it? munish259272 Shell Programming and Scripting 3 11-07-2011 12:31 AM



All times are GMT -4. The time now is 09:57 PM.