linux expect 自动登录交换机保存配置

来源:互联网 发布:网络侵犯著作权案例 编辑:程序博客网 时间:2024/06/08 20:01

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


命令执行:

 ./telnet.exp 192.168.0.80 admin cisco cisco

telnet.exp 命令后参数依次为交换机IP、登录账号、密码、enable密码。

0 0
原创粉丝点击