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

来源:互联网 发布:捕鱼机核心算法 编辑:程序博客网 时间:2024/06/05 06:41

利用pexpect方式完成交换机配置保存。

采用telnet方式登录cisco 3550,输入用户名、密码和enable密码方式登录交换机后,保存交换机配置

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


0 0
原创粉丝点击