這篇文章給大家分享的是有關(guān)linux中expect如何自動(dòng)登錄交換機(jī)保存配置的內(nèi)容。小編覺得挺實(shí)用的,因此分享給大家做個(gè)參考,一起跟隨小編過(guò)來(lái)看看吧。
telnet.exp 文件內(nèi)容如下:
#!/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 命令后參數(shù)依次為交換機(jī)IP、登錄賬號(hào)、密碼、enable密碼。
感謝各位的閱讀!關(guān)于“l(fā)inux中expect如何自動(dòng)登錄交換機(jī)保存配置”這篇文章就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,讓大家可以學(xué)到更多知識(shí),如果覺得文章不錯(cuò),可以把它分享出去讓更多的人看到吧!