[Linuxtrent] Re: Script per Telnet

  • From: Alessandro Carloni <kaya84@xxxxxxxxx>
  • To: linuxtrent@xxxxxxxxxxxxx
  • Date: Mon, 22 Nov 2010 16:11:34 +0100

Il giorno 22 novembre 2010 15:22, Stefano Cirolini <
stefano.cirolini@xxxxxxxxx> ha scritto:

> Puoi postare lo script di expect che usi (o almeno le parti interessate ?)
>
> Lo script generato è il seguente:
#####################################################
#!/usr/bin/expect -f
#
# This Expect script was generated by autoexpect on Mon Nov 22 15:15:38 2010
# Expect and autoexpect were both written by Don Libes, NIST.



set force_conservative 0 ;# set to 1 to force conservative mode even if
;# script wasn't run conservatively originally
if {$force_conservative} {
    set send_slow {1 .1}
    proc send {ignore arg} {
        sleep .1
        exp_send -s -- $arg
    }
}
set timeout -1
spawn $env(SHELL)
match_max 100000
expect -exact "ASISTAR-PBX:~# "
send -- "telnet 10.100.1.105"
expect -exact "telnet 10.100.1.105"
send -- "\r"
expect -exact "\r
Trying 10.100.1.105...\r
Connected to 10.100.1.105.\r
Escape character is '^\]'.\r
\r
login: "
send -- "administrator\r"
expect -exact "administrator\r
password: "
send -- "\r"
expect -exact "\r
10.100.1.105>"
send -- "enable\r"
expect -exact "enable\r
10.100.1.105#"
send -- "configure\r"
expect -exact "configure\r
10.100.1.105(cfg)#"
send -- "copy http://10.100.1.1/devices/00:a0:ba:04:67:c2.cfgstartup-config";
expect -exact "copy
http://10.100.1.1/devices/00:a0:ba:04:67:c2.cfg^[\[52Dtt^[\[1C://10.100.1^[\[2C/devices/00:a0:ba^[\[1C04^[\[1C67^[\[1Cc2.cfg
startup-config"
send -- "\r"
expect -exact "\r
Download...^[\[120D^[\[0KDownload...     10352 Bytes\r
10.100.1.105(cfg)#"
send -- "reload\r"
expect -exact "reload\r
Running configuration has been changed.\r
Do you want to copy the 'running-config' to the 'startup-config'?\r
Press 'yes' to store, 'no' to drop changes : "
send -- "no\r"
expect -exact "no\r
Press 'yes' to restart, 'no' to cancel : "
send -- "yes\r"
expect -exact "yes\r
The system is going down\r
"
expect eof

########################################

Other related posts: