READING stderr from within Awk

Posted by Dave on Stack Overflow See other posts from Stack Overflow or by Dave
Published on 2010-03-24T14:27:51Z Indexed on 2010/03/24 14:43 UTC
Read the original article Hit count: 306

Filed under:
|
|

I want to keep SSH debug info separate (and logged) from other input. However, if I simply redirect stderr to a log file, I risk combining output from SSH and output from the remote process on the host machine (that might send something to stderr):

$ ssh -v somemachine 2> file.log

So, I want to filter out only those lines that match "debug1":

$ ssh -v somemachine | awk '/debug1/ {print > "file.log"; next} {print}'

Good so far, BUT ssh's debug output goes to stderr. So...

$ ssh -v somemachine 2>& | awk '/debug1/ {print > "file.log"; next} {print}'

Foiled again! I don't want to mix stdout and stderr. BAD!

What does a kid like me do? I was about to go the route of named pipes or some such wildeness, but really, all I need to know is how to get awk to match patterns from stderr ONLY.

© Stack Overflow or respective owner

Related posts about awk

Related posts about string-matching