Created
August 21, 2013 18:14
-
-
Save rampantmonkey/6297987 to your computer and use it in GitHub Desktop.
Test ssh access for a list of machines.
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
#!/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] |
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
#!/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