Last active
August 29, 2015 14:14
-
-
Save bruno-/dc4255f6d426af00c240 to your computer and use it in GitHub Desktop.
The venerable "expect" - scripts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 [email protected]\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