#!/bin/bash
#
# Script to check if SSH returns a certain string for password query
#

expect=/usr/bin/expect

if [[ ! -x "$expect" ]]; then
	echo "\"$expect\" was not found, or is not executable"
	exit 3
fi

if [[ "$#" -ne "2" ]]; then
	echo "Usage: check_ssh_response <hostname> <response_regex>"
	exit 3
fi

$expect -f - <<%
	log_user 0

	spawn ssh -o ConnectTimeout=60 $1

	expect {
		eof {
			puts "Error connecting to $1"
			exit 2
		}
                -re "$2"
	}

	puts "SSH ready for service on $1"
	exit 0
"
%
