I am continuing to write an article each month. I add some little title and subtitle to improve the ease of reading. Today, I want to share to you a little trick I use to check if it is possible to establish a SSH connection with a remote host.
- You want to transfer some files with SSH protocol. You want to be sure it is possible to establish a connection and be notified if it is not possible.
- You want to check periodically if it is possible to connect to a remote host with SSH.
What I do
I created a bash script to open a connection with the remote host in SSH and check if it works well. If it doesn't, I send an email to a specific address.
The main part
ScriptsBoth scripts are available in Github following MIT LICENCE. You can find them here.
Script to check ssh connection
Requirement and advice
- You need to have a bash prompt after you connected to ssh.
- You need to have a mail transfer agent properly configured.
- You need to check when you established a SSH connection that you don't receive any warning message from SSH. In this case, the status variable will got another value than "ok" and the script will considered you aren't be able to establish a connection.