0

I was setting to backup the running config but carried out not do as I like, how I can dump the data in txt?

#!/usr/bin/expect -f

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 "example@host:~\$ "
send -- "telnet xxx.xxx.xxx.xxx"
expect -exact "telnet xxx.xxx.xxx.xxx"
send -- "\r"
expect -exact "\r
Trying 180.xxx.xxx.xxx...\r
Connected to 180.xxx.xxx.xxx.\r
Escape character is '^\]'.\r
\r
\r
User Access Verification\r
\r
Username: "
send -- "exampleuser"
expect -exact "exampleuser"
send -- "\r"
expect -exact "\r
Password: "
send -- "examplepasword\r"
expect -exact "\r
CCEMMT01-01>"
send -- "enable\r"
expect -exact "enable\r
Password: "
send -- "examplepasword\r"
expect -exact "\r
CCEMMT01-01#"
send -- "sh run "
expect -exact "\r
CCEMMT01-01#sh running-config "
send -- "\r"
expect -exact "\r
CCEMMT01-01#"
send -- "exit\r"
expect -exact "exit\r
example@host:~\$ "
send -- ""
expect eof
example@host:~$ 
0

I'm thinking your problem is in here:

expect -exact "\r
CCEMMT01-01#"
send -- "sh run "
expect -exact "\r
CCEMMT01-01#sh running-config "
send -- "\r"

It looks like you're sending sh run but then expecting CCEMMT01-01#sh running-config to get printed out, which probably doesn't happen.

try:

expect -exact "\r
CCEMMT01-01#"
send -- "sh running-config \r"

That will wait for the command prompt, then send the sh running-config command.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.