I have the following line in my bash file:
LIST=$(ssh 192.168.0.22 'ls -1 /web');
The problem I am having is that it is a part of automated script and I often get this on the stdout
and not the data I need:
ssh_exchange_identification: Connection closed by remote host
I realize that LIST
only gets the stdout
of the ls
. So I am looking for a command that would get more of the info from the commands. In particular:
stdout
forls
– I have that right nowstderr
forls
– not really interested, I don't expect a problem therestdout
forssh
– Not interested, I don't even know what it would outputstderr
forssh
– THIS IS WHAT I AM LOOKING FOR to check whether itssh
correctly. This being empty should mean that I have the data in$LIST
I expect
Best Answer
From ssh man page on Ubuntu 16.04 (LTS):
Knowing that, we can check exit status of
ssh
command. If exit status was225
, we know that it's anssh
error, and if it's any other non-zero value - that'sls
error.