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
. I tried to run it like this:

$ | 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: | 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. standard output is sent to log.txt and displayed on the terminal.
  2. standard error is just sent to the terminal.


# output to log
# error  to console > log

# output to log and console
# error  to         console | tee log

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

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

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