0

need hide error from the script

for s in $s_list; do
    if [ "${s}" = "test" ]; then
        db_status=$(mysql -h localhost -P 3306 -u test -ptest -e "show create database test;"  | awk {'print $1'} | tail -n 1 )
        db_status_error=$(mysql -h localhost -P 3306 -u test -ptest -e "show create database test;" 2>&1 | awk {'print $1'} | tail -n 1 )
        # echo $db_status_error   
        if [ "$db_status" == "test" ]; then  
            echo "Database exist, need wait..." 
            sleep 2;
        elif [ "$db_status_error" == "ERROR" ] < /dev/null > /dev/null 2>&1 ; then
            echo "Database does not exist" 
            sleep 2;
            exit 0
        fi
    fi
done

result is

ERROR 1049 (42000) at line 1: Unknown database 'test'
Database does not exist

i need just line with Database does not exist

1
  • Hint: the message is probably coming from your db_status=$(...) line, not from your elif [ ... ] line... Commented May 17, 2016 at 17:50

1 Answer 1

1

You need to redirect stderr to /dev/null when you set db_status:

db_status=$(mysql -h localhost -P 3306 -u test -ptest -e "show create database test;" 2> /dev/null | awk {'print $1'} | tail -n 1 )
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.