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 wildness, but really, all I need to know is how to get awk to match patterns from stderr ONLY.