Skip to content

Instantly share code, notes, and snippets.

@badstreff
Last active December 5, 2016 20:56
Show Gist options
  • Save badstreff/91340213ee0c39653e1fbf62e3487897 to your computer and use it in GitHub Desktop.
Save badstreff/91340213ee0c39653e1fbf62e3487897 to your computer and use it in GitHub Desktop.
What did I just write...
#!/usr/bin/expect -f
set password "PASSWORDGOESHERE"
set r 0
spawn ssh -oStrictHostKeyChecking=no admin@localhost exit
expect "assword:" {
send "$password\r"
expect "assword:" {
set r 1
}
}
# If we didn't get prompted twice the password should be correct
if {$r == 0} {
send_user "Password Set Correctly"
exit 0
}
# If we got prompted twice go ahead and check the other possible account
if {$r == 1} {
set r 0
spawn ssh -oStrictHostKeyChecking=no administrator@localhost exit
expect "assword:" {
send "$password\r"
expect "assword:" {
set r 1
}
}
}
# If we didn't get prompted twice the password should be correct
if {$r == 0} {
send_user "Password Set Correctly"
exit 0
}
send_user "Password Not Set"
exit 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment