12-15-2010 09:10 AM - edited 03-06-2019 02:33 PM
Hi to all, i have the following expect script:
proc save_config_to_nvram {} {
send "copy running-config startup-config\r"
expect {
-re "OK" {return 1}
# in case this is the first time the running configuration ever saved to
#NVRAM
-re "confirm" {
send "yes\r"
expect {
-re "OK" {return 1}
timeout {return 0}
}
}
timeout {return 0}
}
}
I saved it in a file and store the file in the flash of the router.
I try to run the script in the following mode:
Router(tcl)#save_config_to_nvram
But i got:
invalid command name "send" ^
% Invalid input detected at '^' marker.
I'm sure the script is correct and i understood that the router is not able to understand "expect" command like "send", "confirm" .
How can i fix it?
Thanks, regard Fabio.
Solved! Go to Solution.
12-16-2010 03:02 AM
fabio.marino wrote:
Thanks Yudong for your time,
cisco devices support TCl so i supposed that they also are able to run expect script.
So you think that i can run expect script on my computer, for example to send command via ssh or telnet to the router/switch but can not run it directly in the devices.
I tried to search documentation on the web about my request and effectively i did not find anything to fix my doubt.
Any one else can give me some explanation for why cisco devices doesn't support expect?
Fabio
TCL was originally written to easily allow extensions to the base tcl shell. The most well known of these extensions are -
1) TK as in TCL/TK which allows you to program Graphical User Interfaces in your programs (think of it as a much easier way to do GUIs than X in Unix).
2) Expect which allows you to write a program that can react to what output is sent back to your script, hence the name Expect.
Both of these extensions use TCL as the base and build on it from there. Cisco IOS TCL is the pure tcl shell and does not include the extensions. So your router will not understand either TK or Expect commands. As previously suggested if you want to run Expect you will need to run it on either a Unix/Linux box or Windows for which there is an Expect version although it works more naturally on Unix as a lot of Expect deals with vtys etc.
However i suspect what you are trying to do could be done with TCL and EEM on the router itself. A TCL/EEM could be used to save the config at regular intervals.
If you would rather try and do it on the router rather than use a separate script then post a new query into the Network Management forum where they deal with these sorts of questions.
Jon
12-15-2010 03:07 PM
I don't think you can run expect script on router directly.
You have to run it on a unix/linux box which supports expect script.
12-16-2010 01:40 AM
Thanks Yudong for your time,
cisco devices support TCl so i supposed that they also are able to run expect script.
So you think that i can run expect script on my computer, for example to send command via ssh or telnet to the router/switch but can not run it directly in the devices.
I tried to search documentation on the web about my request and effectively i did not find anything to fix my doubt.
Any one else can give me some explanation for why cisco devices doesn't support expect?
12-16-2010 03:02 AM
fabio.marino wrote:
Thanks Yudong for your time,
cisco devices support TCl so i supposed that they also are able to run expect script.
So you think that i can run expect script on my computer, for example to send command via ssh or telnet to the router/switch but can not run it directly in the devices.
I tried to search documentation on the web about my request and effectively i did not find anything to fix my doubt.
Any one else can give me some explanation for why cisco devices doesn't support expect?
Fabio
TCL was originally written to easily allow extensions to the base tcl shell. The most well known of these extensions are -
1) TK as in TCL/TK which allows you to program Graphical User Interfaces in your programs (think of it as a much easier way to do GUIs than X in Unix).
2) Expect which allows you to write a program that can react to what output is sent back to your script, hence the name Expect.
Both of these extensions use TCL as the base and build on it from there. Cisco IOS TCL is the pure tcl shell and does not include the extensions. So your router will not understand either TK or Expect commands. As previously suggested if you want to run Expect you will need to run it on either a Unix/Linux box or Windows for which there is an Expect version although it works more naturally on Unix as a lot of Expect deals with vtys etc.
However i suspect what you are trying to do could be done with TCL and EEM on the router itself. A TCL/EEM could be used to save the config at regular intervals.
If you would rather try and do it on the router rather than use a separate script then post a new query into the Network Management forum where they deal with these sorts of questions.
Jon
12-16-2010 08:42 AM
Ok thanks jon.
My idea was just to automize some command as expect allows. I'll search more info through Forum as you indicated.
Bye, Fabio.
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide