Skip to content

Instantly share code, notes, and snippets.

@Gabelbombe
Created January 14, 2015 23:00
Show Gist options
  • Save Gabelbombe/85293461e455d20c38b2 to your computer and use it in GitHub Desktop.
Save Gabelbombe/85293461e455d20c38b2 to your computer and use it in GitHub Desktop.
#!/usr/bin/expect
# Expect login and SU for SSH
# Usage ssh_sudo_login.expect <host> <ssh user> <ssh password> <su user> <su password>
# CPR : Jd Daniel :: Ehime-ken
# MOD : 2015-01-14 @ 14:59:06
# VER : Version 1
set timeout 60
spawn ssh [lindex $argv 1]@[lindex $argv 0]
expect "yes/no" {
send "yes\r"
expect "*?assword" { send "[lindex $argv 2]\r" }
} "*?assword" { send "[lindex $argv 2]\r" }
expect "# " { send "su - [lindex $argv 3]\r" }
expect ": " { send "[lindex $argv 4]\r" }
expect "# " { send "ls -ltr\r" }
interact
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment