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.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-21-2008
mirusnet's Avatar
Registered User
 

Join Date: Dec 2007
Posts: 122
2>&1

I need that if following command return some "warning", the $? must be !=0.

Example:
Code:
mysql  --show-warnings porta-billing -sBe "alter table Env engine=falcon"        
Warning (Code 1286): Unknown table engine 'falcon'
Code:
echo $?
0
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 03-21-2008
matt.d's Avatar
Registered User
 

Join Date: Feb 2008
Location: /dev/null
Posts: 62
You are checking whether or not the UNIX command completed successfully. $? does not report a mysql exception. Since the command got you into mysql successfully, the return code was 0. From my experience, I don't think it is possible to have it return another value.
Reply With Quote
  #3 (permalink)  
Old 03-22-2008
Registered User
 

Join Date: Jan 2008
Posts: 182
I would agree,its either a 0 or 1..

How ever you could use "ur command" 2> /"error file"
then
cat "error file"

if there is any error in running the command with the arguments that you have specified then you can check the errors by visiting the "error file"...

might help in debugging
Reply With Quote
  #4 (permalink)  
Old 03-25-2008
Registered User
 

Join Date: Sep 2007
Location: Poland
Posts: 63
1. Think about other language. Shell scripts are not designed for database manipulation.
2. You could try this:
Code:
#!/bin/ksh
typeset error=0
typeset retval=0
typeset my_path=$(pwd)
mysql whatever 1>$$output.txt 2>$$error.txt
retval=$?
cd "$my_path"
if [[ -s $$error.txt ]]; then
error=1
fi
if [[ -n $(cat $$output.txt|grep 'my error string that I am expecting') ]] ;then
error=2
fi
if [[ $retval -ne 0 ]] ;then
return $retval
else
return $error
fi
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 03:09 PM.


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

Content Relevant URLs by vBSEO 3.2.0