Skip to content

Instantly share code, notes, and snippets.

@hjzheng
Last active October 27, 2015 02:59
Show Gist options
  • Save hjzheng/b8c778dbb0c713394de5 to your computer and use it in GitHub Desktop.
Save hjzheng/b8c778dbb0c713394de5 to your computer and use it in GitHub Desktop.
用于iTerm2的自动telnet脚本
#!/usr/bin/expect #Where the script should be run from.
#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 "Username:"
#The script sends the user variable
send "$user\n"
#The script expects Password
expect "Password:"
#The script sends the password variable
send "$password\n"
#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