1
I am calling applications from my shell script, which performs a number of important steps in sequence, one step being below:
for database in $(
echo 'show databases;' |
mysql --defaults-extra-file=/etc/sqlbackup/my.cnf \
-e 'show databases' -s --skip-column-names|
grep -vi information_schema )
do
echo $database
done
exit 0
I am able to be able to log the output to the screen, that I am doing via the echo function.
My question is what would happen if an application (any command line called from the script), cannot connect and chucked an error such as:
`ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)`?
Are errors reported in a separate environment variable outside the string output, if so how can I detect this? How would one change the path the script takes depending on success or failure?
I am a .Net programmer and the best analogy i can make is where an exception is thrown and handeled:
catch (Exception e)
{
// log the reason here: echo "error running database command: " + e.Description
}
Is there something similar to the above but for borne/bash shell?
Read whole thing or only about redirection here and here. If none of that makes sense, you should probably check out bash for beginners and ABS. Happy learning!
– Ярослав Рахматуллин – 2013-04-05T13:40:44.697