0

I have a BASH script that logs in to multiple servers and runs a series of commands. Occasionally I'll have instances where a server is unavailable (regular maintenance, etc). How can I exit out of the SSH session cleanly without passing an error like this?:

bash-3.2$ ssh myserver3
Disconnecting: Bad packet length.
Ken J
  • 4,312
  • 12
  • 50
  • 86

1 Answers1

1

You may be looking for -q option:

ssh -q user@host

And you can check the return code $? afterwards.

From man bash:

-q

Quiet mode. Causes all warning and diagnostic messages to be suppressed

You can find more info about this topic in How to create a bash script to check the SSH connection?.

Community
  • 1
  • 1
fedorqui
  • 275,237
  • 103
  • 548
  • 598