I am new to shell scripting. I am trying to write a shell script in which i can run mysql commands after reading from the file. I have to capture the output of the sql commands in a separate file. Following is the code :
mysql -h ${DB_SERVER} -P ${DB_PORT} -u ${USER} -p${PASS} -f < createUsers.sql >> install.log
Shell script takes a few inputs from the user. When i run the shell script and if i specify a wrong password, the error shows up on the console but not in the log file.
Please suggest how can i redirect the error to the log file as well.
Add 2>&1
on to the end to also capture stderr. Standard out is file descriptor 1 and standard error is 2, so this redirects stderr to wherever stdout 1 is going, i.e. install.log.
mysql [options] < createUsers.sql >> install.log 2>&1
Note: The order of redirections matters. Make sure you put it after the >>
, not before it.
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