Skip to content

Instantly share code, notes, and snippets.

@rampantmonkey
Created August 21, 2013 18:14
Show Gist options
  • Save rampantmonkey/6297987 to your computer and use it in GitHub Desktop.
Save rampantmonkey/6297987 to your computer and use it in GitHub Desktop.
Test ssh access for a list of machines.
#!/usr/bin/expect
# Usage: ./ssh_test.exp MACHINE_NAME crobins9 ******
set timeout 7
set machine [lindex $argv 0]
set user [lindex $argv 1]
set password [lindex $argv 2]
spawn ssh -oStrictHostKeyChecking=no "$user@$machine"
expect {
-re "$user@$machine's password:" {
send "$password\r";
exp_continue
} -re "~" {
send "exit\r";
exp_continue
} -re "yes" {
send "yes\r";
exp_continue
}
}
catch wait result
exit [lindex $result 3]
#!/usr/bin/env bash
domain='cse.nd.edu'
machine_list='machines'
username=$1
password=$2
while read machine; do
fqmn=$machine.$domain
(./ssh_test.exp $fqmn $username $password >/dev/null 2>&1) &
wait $!
if [ $? -ne 0 ]; then
echo $fqmn
fi
done < "$machine_list"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment