I'm trying to test ssh connectivity similar to the one done by this script but on a local host. The problem with the script below (which I didn't write) is that it requires ssh_pass and does not allow a check on localhost. I've been reading that an expect script might do the trick. I have tried it, but don't have any luck.
Any help would be greatly appreciated!
#!/bin/bash
STATE_OK=0
STATE_WARNING=1
STATE_CRITICAL=2
STATE_UNKNOWN=3
EXPECTED_RESULT_STRING="This account is currently not available."
while [ $# -gt 0 ]; do
case $1 in
-h|--help) help; exit $STATE_OK;;
-H|--hostname) shift; host=$1; shift;;
*) usage; exit $STATE_UNKNOWN;;
esac
done
usage () {
echo "\
Kerberos 5 KDC plugin for Nagios
-H, --hostname=HOST Name of KDC to check
-h, --help Print this help"
}
help () {
echo; usage;
}
ssh_result=$((/usr/bin/sshpass -f /var/spool/nagios/nagioscheck ssh -o StrictHostKeyChecking=no nagioscheck@$host ) 2>&1)
return_code=$?
echo "$ssh_result"
if [ $grep_status == 0 ]
then
echo "OK ssh login successful and /sbin/nologin exited our session"
exit $STATE_OK
else
echo "invalid command line arugment or possible issue with /sbin/nologin on host"
echo "SSH message: $ssh_result"
exit $STATE_UNKNOWN
fi
;;
5)
echo "CRITICAL SSH password auth failed. Authentication is probably down"
echo "SSH error message: $ssh_result"
exit $STATE_CRITICAL
;;
255)
echo "UNKOWN SSH connection failed for an unknown reason. Return code 255, try checking for a stale known host in /var/spool/nagios/"
echo "SSH error message: $ssh_result"
exit $STATE_UNKNOWN
;;
*)
echo "UNKOWN sshpass failed for an unknown reason. Return code was $return_code"
echo "SSH error message: $ssh_result"
exit $STATE_UNKOWN
;;
esac