Printing Terminal Output to a Error File

I am having a bash script which is basically invoking a python program to validate the Source Query results against the target query results. I am placing all the queries in a .sql file.

I want to write to a Error log file incase if the syntax is wrong or if the column is not present in the table.

When i run my script as

bash script.sh

its displaying the error as

*** Failure 5628 Column SYS_CDE not found in RESERVATION.
                Statement# 1, Info =0

I want to capture this error in a error log file.

When I make use of the following command

bash script.sh > error_log_file

, its not writing the terminal output to the error file.

Any help is appreciated.

Thanks

Diagnostics are usually written to the standard error output (file descriptor 2) instead of standard output (file descriptor 1). Try:

bash script.sh 2> error_log_file
1 Like

Thanks a bunch its working..

I have the error_log_file inside the script. Is there anyway that I can make this happen inside a script i.e. appending the terminal output to the error_log_file which contains all the Query validation results.

There are several ways to redirect a file inside a script. If you tell us what operating system and shell you are using, show us the script, and specify which commands inside the script should have output redirected into which file(s); we can show you how to do that. (You could also just look for "redirection" on the man page on your system for the shell you are using.)

The second line of the following can be redirected with "2>" the same as anything else written to stderr if you were looking for a way to redirect standard output.

echo output
echo error >&2