Skip to content

Instantly share code, notes, and snippets.

@joaompinto
Created February 18, 2016 17:07
Show Gist options
  • Save joaompinto/eff3453a5cfabbf564c8 to your computer and use it in GitHub Desktop.
Save joaompinto/eff3453a5cfabbf564c8 to your computer and use it in GitHub Desktop.
Connect to system with expect
#!/usr/bin/expect -f
set target [lindex $argv 0];
set timeout 60
# Request the login password
stty -echo
send_user -- "Password for $target: "
expect_user -re "(.*)\n"
send_user "\n"
stty echo
set pass $expect_out(1,string)
#Connect using ssh
set timeout 2
spawn ssh -oStrictHostKeyChecking=no -oCheckHostIP=no $target
expect "?assword:"
send "$pass\n"
expect "$"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment