Skip to content

Instantly share code, notes, and snippets.

@diegogslomp
Last active January 31, 2016 00:50
Show Gist options
  • Save diegogslomp/fda6f6363ebb3c002c81 to your computer and use it in GitHub Desktop.
Save diegogslomp/fda6f6363ebb3c002c81 to your computer and use it in GitHub Desktop.
Telnet script using expect
#!/usr/bin/expect #Where the script should be run from.
# Copied from http://osix.net/modules/article/?id=30
#If it all goes pear shaped the script will timeout after 20 seconds.
set timeout 20
#First argument is assigned to the variable name
set name [lindex $argv 0]
#Second argument is assigned to the variable user
set user [lindex $argv 1]
#Third argument is assigned to the variable password
set password [lindex $argv 2]
#This spawns the telnet program and connects it to the variable name
spawn telnet $name
#The script expects login
expect "login:"
#The script sends the user variable
send "$user "
#The script expects Password
expect "Password:"
#The script sends the password variable
send "$password "
#This hands control of the keyboard over two you (Nice expect feature!)
interact
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment