How to get nicer error-messages in this bash-script?

Posted by moata_u on Ask Ubuntu See other posts from Ask Ubuntu or by moata_u
Published on 2011-03-07T16:15:17Z Indexed on 2011/03/08 0:18 UTC
Read the original article Hit count: 192

Filed under:
|

I'm trying to catch any error when run a command in order to write a log-file / report

I've tried this code:

    function valid (){

    if [ $? -eq 0 ]; then
     echo "$var1" ": status : OK" 
     else echo "$var1" ": status : ERROR"   
    fi
   }

function save(){

 sed -i "/:@/c connection.url=jdbc:oracle:thin:@$ip:1521:$dataBase" $search
 var1="adding database ip"
 valid $var1

 sed -i "/connection.username/c connection.username=$name" #$search
 var1="addning database SID"
 valid $var1
}
save

The output looks like this:

adding database ip : status : OK
sed: no input file

But I want it to look like this:

adding database ip : status : OK
sed: no input file : status : ERROR"

or this:

adding database ip : status : OK
addning database SID : status : ERROR"

I've been trying, but it's not working with me. :(

© Ask Ubuntu or respective owner

Related posts about command-line

Related posts about bash