Skip to content

Instantly share code, notes, and snippets.

@bruno-
Last active August 29, 2015 14:14
Show Gist options
  • Save bruno-/dc4255f6d426af00c240 to your computer and use it in GitHub Desktop.
Save bruno-/dc4255f6d426af00c240 to your computer and use it in GitHub Desktop.
The venerable "expect" - scripts
#!/usr/bin/expect
# start ssh process
spawn ssh root@expect
# expect this string on the screen
expect "password"
# type this to the screen
send "foobar123\r"
expect "root@expect2"
# return control to the user
interact
#!/usr/bin/expect
# the script won't make output
log_user 0
spawn ssh root@expect
expect "password"
send "foobar123\r"
expect "root@expect2"
puts "successfully logged in!"
send "\r"
interact
#!/usr/bin/expect
# the script won't make output
log_user 0
set timeout 10
spawn ssh root@expect
expect "password"
send "foobar123\r"
expect {
"root@expect2" {
puts "successfully logged in!"
send "\r"
}
timeout { puts "Fail"; exit 1 }
}
interact
#!/usr/bin/expect
# the script won't make output
log_user 0
set timeout 10
spawn ssh root@expect
expect "password"
send "foobar123\r"
expect {
"root@expect2" {
puts "first hop successful"
}
timeout { puts "Fail"; exit 1 }
}
send "ssh root@104.236.13.122\r"
expect "password"
send "foobar456\r"
expect {
"root@expect3" {
puts "second hop successful"
send "\r"
}
timeout { puts "Fail"; exit 1 }
}
interact
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment