banderas20
Active Member
Hi!
I'm writing a shellscript to check whether a server is reachable via SSH.
I assign the SSH command output to a shell variable so I can tell if it works or not.
I also limit the time with the timeout command. So my script looks like this:
Possible expected values of "OUTPUT":
I have a problem with the value of the variable.
From the prompt,
But If I run the script, OUTPUT variable is always empty. As if the server was always unreachable.
The same happens If I run from the prompt:
Maybe it has something to do with the assignation to the variable?
Thanks for the help!
I'm writing a shellscript to check whether a server is reachable via SSH.
I assign the SSH command output to a shell variable so I can tell if it works or not.
I also limit the time with the timeout command. So my script looks like this:
OUTPUT=$(timeout 60s ssh user@server)
Possible expected values of "OUTPUT":
- empty string -> time runs out and "timeout" cancels the SSH command.
- "user@server's password:" -> the server answers and prompts for password.
- "ssh: connect to server port 22: Connection timed out" -> the system exceeds the timeout and I receive this specific error.
I have a problem with the value of the variable.
From the prompt,
ssh user@server
succeeds in less than one minute, giving the expected output.timeout 60s ssh user@server
also gives the expected result.But If I run the script, OUTPUT variable is always empty. As if the server was always unreachable.
The same happens If I run from the prompt:
OUTPUT=$(timeout 60s ssh user@server).
echo $OUTPUT shows nothing.Maybe it has something to do with the assignation to the variable?
Thanks for the help!