Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm half way through writing a nagios script and I've hit an annoyance with SSH.

According to the man page:

-q       Quiet mode.  Causes all warning and diagnostic messages to be
         suppressed.

Yet if I enable the quiet flag and then pass an invalid port, I still get an error:

$ ssh user@localhost -q -p test
Bad port 'test'

This is a problem, because that will make that message the first line out and that's what is grabbed by Nagios. I need to output something like "Warning|SSH error" after picking up on a != 0 exit code from ssh, but the first line I can output on is going to be line 2.

How can I make SSH TRULY quiet?

Note: I wasn't sure whether to post this question on serverfault, on superuser or on stackoverflow. I went with serverfault as the user base are probably most experienced with cli SSH and cli scripting workarounds.

share|improve this question
1  
Not that it really helps, but it looks like the manual has been updated to reflect this. As of OpenSSH 5.8 (and maybe earlier), it states that "most warnings and diagnostics" will be suppressed, instead of "all warnings and diagnostics". –  James Sneeringer Jan 12 '12 at 22:37
    
heh annoying! good spot though. –  SimonJGreen Jan 12 '12 at 22:41
    
Why not just avoid trying to connect to an invalid port? –  Zoredache Jan 12 '12 at 22:43
    
@Zoredache This is error catching/handling. Avoiding a typo doesn't solve the problem of how to handle one gracefully ;) –  SimonJGreen Jan 13 '12 at 9:50

1 Answer 1

up vote 7 down vote accepted
ssh user@localhost -q -p test 2> /dev/null 

will redirect stderr to /dev/null.

share|improve this answer
    
Now I feel like a complete tit. Will teach me to be coding late at night! –  SimonJGreen Jan 12 '12 at 22:39

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.