3

In my bash file I have the following

result=$(mysql --login-path=remote_user --database=mydatabase < "import.sql");
echo $result;

I am trying to capture the output so that if it errors I can email myself

When I run the command I get

ERROR 1062 (23000) at line 1:....

But $result is always empty so how can I assign / capture the error so that I can then use this in the email

Note: I have enforced the error so that I can test

goose84
  • 282
  • 1
  • 2
  • 15

1 Answers1

1

Got it to work for anyone else who has this issue

        resultfile="result.txt";
        result=$(mysql --login-path=remote_user --database=mydatabase < "import.sql"  2>&1 ) || echo $result > $resultfile
        if [ -f $resultfile ]; then
            echo "DO SOMETHINNG"
        fi
goose84
  • 282
  • 1
  • 2
  • 15