16
3
#!/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 ...
16
3
#!/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 ...
9
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.
31
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
6
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.
1There is problem here, if i want to log the output, this will not help. But other than that its good. – indianwebdevil – 2018-10-09T05:27:39.153
-1
Could not comment on Fran's answer which is the correct one.
Just wanted to add that your code fragment looks like a script, which means you are likely calling remote stuff which is not depending on an interactive screen (unlike for example mc
or top
which make little sense without a keyboard and a screen - you will therefore not use these programs in scripts).
So you are better off explicitly without a terminal. That means replace the -t flag with the -T flag. Longer syntax which I prefer in scripts to make them more self evident and readable would be: -o 'RequestTTY no'
vs. -o 'RequestTTY yes'
.
And while at that, forget the -o LogLevel=QUIET
solution suggested by Leo - it hides error messages too. If your script faces some unfavourable circumstances, you will not understand what went wrong. In scripts you probably want to use -o LogLevel=ERROR
- this suppresses the remote machine's banner if it has one, but lets error messages through.
This should be the accpeted answer to me – Nam G VU – 2018-07-22T11:29:40.067
Perhaps this answer should be accepted! – indianwebdevil – 2018-10-09T05:26:53.380