cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1665
Views
0
Helpful
4
Replies

Run an exepect script

fabio.marino
Level 1
Level 1

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.

1 Accepted Solution

Accepted Solutions

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

View solution in original post

4 Replies 4

Yudong Wu
Level 7
Level 7

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.

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.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

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.

Getting Started

Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the community:

Innovations in Cisco Full Stack Observability - A new webinar from Cisco