0

I have a script which is checking a database for errors based on a text file of record ids.

When an error occurs such as the connection is lost,it writes the offending id ($line) to a log file as well as the error message ($OP).

Problem is the error message is always null although the error is displayed on the console, only the id is written to the log file.

How can I capture the error and also output that to the log file ??

while read line
do
    OP=$(mysql $DB -u root --password=$PW -e "select * from properties where hierarchyid = $line")
    printf "\r$line"
    #if [ $? -gt 0 ]; then
    if [[ ! $OP =~ "hierarchyid" ]]; then
        echo
        echo $line $OP >> errors.log
        sleep 10    
        echo
    fi
done < $IDS

1 Answer 1

3

Redirect stderr to stdout.

OP=$(mysql ... 2>&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.