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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With