cancel
Showing results for 
Search instead for 
Did you mean: 

Cisco/Expect Help

Michael Lyon
Frequent Advisor

Cisco/Expect Help

Hello All,

I am having a bugger of a time getting this script to function. Its purpose is to log into a remote router, execute a `copy tftp run`, and exit.

The script does log into the router, but never seems to execute the `copy tftp run` portion.

Can anyone please help?

#!/usr/bin/expect -f
#
#
#
#
# usage: upload-config hostname username password configfilename
#
#
#
if { [llength $argv] < 5} {
puts "usage: upload hostname username password tftpip confgfilename"
exit 1
}
set router [lindex $argv 0]
set username [lindex $argv 1]
set password [lindex $argv 2]
set tftpip [lindex $argv 3]
set confgfilename [lindex $argv 4]
set timeout 20

log_user 0
spawn telnet $router

expect {
"Username:" {send $username\r}
}

expect {
"Password:" {send $password\r}
}

expect {
"#" {send "copy tftp run\n"}
}

expect {
"Address" {send $tftpip\r}
}

expect {
"Source" {send $confgfilename\r}
}

expect {
"Destination" {send "run\r"}
}

sleep 15

exit 0
2 REPLIES
Vernon Brown_4
Trusted Contributor

Re: Cisco/Expect Help

Script looks Ok; I did notice that the expect {
" " {send xxx } for the line in question ends with \n whereas all the others end with \r

(newline vs return)

This may have some effect.
{send "copy tftp run\n"}
vs
{Destination" {send "run\r"}

I would try replacing the \n with \r just for kicks :o)

Vern
Stuart Browne
Honored Contributor

Re: Cisco/Expect Help

No cisco gives a '#' at login from external that I'm aware of.

It gives a 'Name>' prompt first, then you have to jump into enabled mode before using the 'copy' command.

It'd help if you'd show us the output, the failure, when you do this command, but you'll need to change 'log_user 0' to 'log_user 1' (i.e. show you what it's doing).
One long-haired git at your service...