Ssh – Making ssh truly quiet

bashnagiosssh

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.

Best Answer

ssh user@localhost -q -p test 2> /dev/null 

will redirect stderr to /dev/null.