linux expect Autologon Switch Save Configuration Method

  • 2021-06-28 14:45:43
  • OfStack

The contents of the telnet.exp file are as follows:


#!/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

Command Execution:

./telnet.exp 192.168.0.80 admin cisco cisco

After the telnet.exp command, the parameters are switch IP, login account, password, enable password.


Related articles: