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

时间:2022-07-27
本文章向大家介绍linux expect 自动登录交换机保存配置的方法,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

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 "$usernamer";exp_continue }
 "*assword" { send "$passwordr"; exp_continue }
 "*>" { send "enabler" ; exp_continue }
 }


expect {
 "*assword" { send "$superpasswordr"; exp_continue }
 "*#" { exp_send "wr r";}
 }

exp_send "quitr"
expect eof

命令执行:

./telnet.exp 192.168.0.80 admin cisco cisco

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

以上这篇linux expect 自动登录交换机保存配置的方法就是小编分享给大家的全部内容了,希望能给大家一个参考。