编写
expect脚本。
这是一个例子:
#!/usr/bin/expect#If it all goes pear shaped the script will timeout after 20 seconds.set timeout 20#First argument is assigned to the variable nameset name [lindex $argv 0]#Second argument is assigned to the variable userset user [lindex $argv 1]#Third argument is assigned to the variable passwordset password [lindex $argv 2]#This spawns the telnet program and connects it to the variable namespawn telnet $name #The script expects loginexpect "login:" #The script sends the user variablesend "$user "#The script expects Passwordexpect "Password:"#The script sends the password variablesend "$password "#This hands control of the keyboard over to you (Nice expect feature!)interact
跑步:
./myscript.expect name user password



