telnet.exp 文件內容如下:
#!/usr/bin/expect -f set ip [lindex $argv 0 ] set username [lindex $argv 1 ] set password [lindex $argv 2 ] set superpassword [lindex $argv 3 ] set timeout 10 spawn telnet $ip expect { "name" { send "$username\r";exp_continue } "*assword" { send "$password\r"; exp_continue } "*>" { send "enable\r" ; exp_continue } } expect { "*assword" { send "$superpassword\r"; exp_continue } "*#" { exp_send "wr \r";} } exp_send "quit\r" expect eof
命令執(zhí)行:
./telnet.exp 192.168.0.80 admin cisco cisco
telnet.exp 命令后參數依次為交換機IP、登錄賬號、密碼、enable密碼。
以上這篇linux expect 自動登錄交換機保存配置的方法就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持腳本之家。