2

So I am attempting to use expect to automate backing up the running config of some switches on our network. The problem that I'm running into is its changing a part of my send commands and I dont know how to fix it.

For example I'm using whats below.

#/usr/bin/expect

spawn /usr/bin/plink -ssh x.x.x.x

expect -exact "User Name:"

send "USERNAME\r"

expect -exact "Password:"

send "PASSWORD\r"

send "copy running-config flash:\\startup-config"

expect "Overwrite file [startup-config] ?[Yes/Press any key for no]"

send "y\r"

expect "Copy succeeded"

send "exit/r"

expect "eof"

but it ends up messing up on "flash:\\startup-config" instead sending "flash:\startup-config" and I'm at a loss as to what this is called (in order to search how to fix it).

Is anyone able to help with pointing me in the right direction?

GTerry
  • 23

1 Answers1

1

Tcl uses the \ character to escape things, like you used \r for the newline. If you want to send a single \ you either have to escape it with an other \, so it becomes \\ or you escape the string with braces {} which will prevent such special escapes. Your options are therefore:

send "copy running-config flash:\\\\startup-config"

or

send {copy running-config flash:\\startup-config}