Simpler Navigation for Servers and Operating Systems - Please Update Your Bookmarks
Completed: a much simpler Servers and Operating Systems section of the Community. We combined many of the older boards, so you won't have to click through so many levels to get at the information you need. Check the consolidated boards here as many sub-forums are now single boards.
If you have bookmarked forums or discussion boards in Servers and Operating Systems, we suggest you check and update them as needed.
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...