Skip to content

Instantly share code, notes, and snippets.

@kocoten1992
Created February 10, 2019 09:28
Show Gist options
  • Save kocoten1992/42eb2cb3497907b7587b0eecc020a29a to your computer and use it in GitHub Desktop.
Save kocoten1992/42eb2cb3497907b7587b0eecc020a29a to your computer and use it in GitHub Desktop.
check we could establish ssh connection using bash
#!/bin/bash
# source http://mindspill.net/computing/linux-notes/bash-script-to-check-ssh-connection/
ssh -q -o BatchMode=yes -o ConnectTimeout=10 example.com exit
if [ $? -ne 0 ]
then
# Do stuff here if example.com SSH is down
echo 'Can not connect to example.com' | mail -s "example.com down" whoever@wherever
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment