How to remove 'connection to xx.xxx.xx.xxx closed' message?

#!/bin/bash

ssh -t $SSH "
    some
    commands
"

Where is the 'connection to xx.xxx.xx.xxx closed' message coming from? I can't stop it even with result=ssh ...


Solution 1:

That is coming from SSH. You see it because you gave the -t switch, which forces SSH to allocate a pseudo-terminal for the connection. Traditionally, SSH displays that message to make it clear that you are no longer interacting with the shell on the remote host, which is normally only a question when SSH has a pseudo-terminal allocated.

Solution 2:

if you add -o LogLevel=QUIET to the SSH command line, that message should disappear:

ssh -o LogLevel=QUIET -t $SSH "
      some 
      commands
"

You can also add it to the ~/.ssh/config file as a line saying LogLevel QUIET

Solution 3:

As Fran mentioned, this is coming about because of the -t switch. You can hide the message by appending:

 2> /dev/null

Your code would look like this:

#!/bin/bash

ssh -t $SSH "
    some
    commands
" 2> /dev/null

This redirects STDERR to /dev/null. Keep in mind all error messages that may be raised will also be redirected to /dev/null and so will be hidden from view.

Solution 4:

I know this is a pretty old question but it pops up in searches.

A better answer is here: How to hide or edit a message on closure of a ssh ,when ssh was handled using interact in expect script.

Basically, use the ssh -q option - it worked perfect for me.