Run an exepect script

Answered Question
Dec 15th, 2010

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.

I have this problem too.
0 votes
Correct Answer by Jon Marshall about 3 years 4 months ago

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

  • 1
  • 2
  • 3
  • 4
  • 5
Average Rating: 5 (1 ratings)
kwu2 Wed, 12/15/2010 - 15:07

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.

fabio.marino Thu, 12/16/2010 - 01:40

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?

Correct Answer
Jon Marshall Thu, 12/16/2010 - 03:02

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

fabio.marino Thu, 12/16/2010 - 08:42

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.

Actions

Login or Register to take actions

This Discussion

Posted December 15, 2010 at 9:10 AM
Stats:
Replies:4 Avg. Rating:5
Views:523 Votes:0
Shares:0
Tags: No tags.

Discussions Leaderboard

Rank Username Points
1 15,007
2 8,155
3 7,730
4 7,083
5 6,742
Rank Username Points
140
72
69
65
45