Skip to content

Instantly share code, notes, and snippets.

@simonmcc
Created December 9, 2014 18:24
Show Gist options
  • Save simonmcc/496271eddc43045f851e to your computer and use it in GitHub Desktop.
Save simonmcc/496271eddc43045f851e to your computer and use it in GitHub Desktop.
#!/usr/bin/expect -f
#
# I got tired of messing up my SSO password since we don't have ssh key logins
set user mccartsi
set server [lindex $argv 0]
set pass [exec security find-generic-password -a $user -s "HP Cloud SSO" -w]
trap { # trap sigwinch and pass it to the child we spawned
set rows [stty rows]
set cols [stty columns]
stty rows $rows columns $cols < $spawn_out(slave,name)
} WINCH
set timeout 30
send_user "connecting to $server\n"
spawn -noecho ssh -oStrictHostKeyChecking=no $user@$server
#login handles cases:
# login with keys (no user/pass)
# user/pass
# login with keys (first time verification)
expect {
"password: " {
send $pass\n
expect {
"> " { }
"$ " { }
}
}
"(yes/no)? " {
send "yes\n"
expect {
"> " { }
"$ " { }
}
}
default {
#interact -o -re "talk: respond with: talk (\[ ^ \r]*)\[ \r]" {
# exec ssh-keygen -R interact_out( 1, string) &
# }
# This doesn't work exactly like I want yet. Since I use a ~/.ssh/config like this.
send_user "Login failed try removing the known_hosts key\n"
send_user "ssh-keygen -R $server\n"
exit
}
}
interact
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment