return 0 return 0 - 5 years ago 285
Bash Question

How to suppress I/O error message for BOTH terminal output and text log (tee)?

In my program, there will be a few seconds that the program writes data to a SSD that's not connected (i.e. writing to a empty bus host). As a result, there must be some I/O error messages output to the terminal during this time.

Besides writing the output to the terminal, I also need to record the progress of the program, but NOT the I/O error messages. The following is a snapshot of the error messages:

5-1Input/output error

Input/output error]! at block#[
]! at block#[Input/output error

WARNING: write errno[ 5
WARNING: write errno[ 5]! at block#[4773881Input/output error
Input/output error
146524727614844WARNING: write errno[ Input/output error
5]! at block#[], ret = ]! at block#[], ret = 13281183], ret = -1
WARNING: write errno[ Input/output errorWARNING: write errno[ 5]! at block#[234468], ret = -1-1


This is the tip of a huge iceberg of I/O error messages. My script file is called
run.sh
. I tried to run it like this:

$ run.sh | tee log.txt 2>&1


But it is not effective.. Is there anything wrong with this command, if not, what would be the problem? Are there other ways to accomplish this?

Answer Source

Here:

run.sh | tee log.txt 2>&1

You are redirecting the standard error of tee to its standard output.
But this looks like it should be doing what you want (though the 2>& is not needed) as tee does not generate error messages.

  1. run.sh standard output is sent to log.txt and displayed on the terminal.
  2. run.sh standard error is just sent to the terminal.

Try:

# run.sh output to log
# run.sh error  to console
run.sh > log

# run.sh output to log and console
# run.sh error  to         console
run.sh | tee log

# run.sh error to same place as output
# run.sh output to console
run.sh 2>&1

# run.sh error to same place as output
# run.sh output to log
run.sh  > log  2>&1

# run.sh error to same place as output
# run.sh output to console and log
run.sh 2>&1 | tee log
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download