简体   繁体   中英

How to redirect bash stderr to terminal, but also redirect stderr with stdout to log file?

I have a script that QA Manager runs. I want him to take a look at terminal from time to time to take a note if any errors appear.

The problem is that the script have a ton of output that we do not need to see.

What I am trying to implement:

  • stderr only goes to terminal
  • stdout only goes to full-log.txt
  • stderr goes to full-log.txt as well as stdout

Another way is to

  • stderr with stdout go to full-log.txt
  • stderr only go error-log.txt

Will be very grateful if someone can help with that.

with bash, using a process substitution, with the redirections performed in this order:

cmd 2> >(tee -a full-log.txt) >full-log.txt

Demo:

$ { echo "this is stdout"; echo "this is stderr" >&2; } 2> >(tee -a full-log.txt) >full-log.txt
this is stderr
$ cat full-log.txt
this is stdout
this is stderr

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM