Created
April 7, 2016 10:53
-
-
Save mikesimons/a24181bcfd48e56479ce6c417e8b6441 to your computer and use it in GitHub Desktop.
Script for testing access to a single ssh host.Loop with something like: cat ~/my-hosts | xargs -I X bash -c 'echo -n "X: " && ssh-test.sh myusername@X'
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
main() { | |
declare host="$1" | |
ssh -oUserKnownHostsFile=/dev/null -oStrictHostKeyChecking=no -oBatchMode=yes -oConnectTimeout=5 -vvv $host -- exit > /tmp/sshtest 2>&1 | |
if [[ $? == 0 ]]; then | |
echo "OK" | |
exit | |
fi | |
if cat /tmp/sshtest | grep "^ssh:.*Connection refused" > /dev/null; then | |
echo "CONNECTION REFUSED" | |
exit 1 | |
fi | |
if cat /tmp/sshtest | grep "^Permission denied" > /dev/null; then | |
echo "PERMISSION DENIED" | |
exit 2 | |
fi | |
if cat /tmp/sshtest | grep "^ssh:.*Connection timed out" > /dev/null; then | |
echo "TIMEOUT" | |
exit 3 | |
fi | |
echo "UNKNOWN" | |
exit 4 | |
} | |
main $@ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment