cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Announcements

1865
Views
10
Helpful
14
Replies
Highlighted
Beginner

TCL - Clear AUX line

Dear friends,

I need to create a script that will clear aux line and test dial backup.  I'm planning an interaction between EEM and TCL.

I tested the following:

event manager applet TEST

event none

action 1.0 cli command "enable"

action 2.0 cli command "tclsh flash:test.txt"

TCL script (test.txt):

set clear_line [exec "clear line aux 0"]

...

My script stops at "clear line" because IOS expects me to press ENTER to confirm clearing of the line.  My IOS version does not provide EEM's pattern option of the cli like that:

action 1.0 cli command "clear line aux 0" pattern "[confirm]"

This would solve my issue, but, I as said, my version doesn't have this pattern option.

How can I do that?

thank you!

Everyone's tags (4)
1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Hall of Fame Cisco Employee

Re: TCL - Clear AUX line

Sorry, try this instead:

::cisco::eem::event_register_none 

namespace import ::cisco::eem::*
namespace import ::cisco::lib::*

array set arr_einfo [event_reqinfo]


if [catch {cli_open} result] {
    error $result $errorInfo
} else {
    array set cli1 $result
}

if [catch {cli_exec $cli1(fd) "enable"} _cli_result] {
    error $_cli_result $errorInfo
}

if [catch {cli_write $cli1(fd) "clear line aux 0"} _cli_result] {
    error $_cli_result $errorInfo
}

if [catch {cli_read_pattern $cli1(fd) "confirm"} result] {
    error $result $errorInfo

}

if [catch {cli_exec $cli1(fd) "y"} _cli_result] {
    error $_cli_result $errorInfo
}


# Close open cli before exit.
catch {cli_close $cli1(fd) $cli1(tty_id)} result

View solution in original post

14 REPLIES 14
Highlighted
Hall of Fame Cisco Employee

TCL - Clear AUX line

Use an EEM Tcl policy instead:

::cisco::eem::event_register_none 

namespace import ::cisco::eem::*
namespace import ::cisco::lib::*

array set arr_einfo [event_reqinfo]


if [catch {cli_open} result] {
    error $result $errorInfo
} else {
    array set cli1 $result
}

if [catch {cli_exec $cli1(fd) "enable"} _cli_result] {
    error $_cli_result $errorInfo
}

if [catch {cli_exec $cli1(fd) "clear line aux 0"} _cli_result] {
    error $_cli_result $errorInfo
}

if [catch {cli_exec $cli1(fd) "y"} _cli_result] {
    error $_cli_result $errorInfo
}


# Close open cli before exit.
catch {cli_close $cli1(fd) $cli1(tty_id)} result

Register this as an EEM Tcl policy (call it clear_aux.tcl), and you won't need tclsh.

Highlighted
Beginner

TCL - Clear AUX line

Hi, Joseph,

Thanks for replying me.  My routine shall make some more steps.  May I add them to this code with no problem (steps like adding and removing routes, pinging destinations and so on)?

To register as a policy, I simply make:

event manager policy flash:clear_aux.tcl type user

Is it all?

Regards

Highlighted
Hall of Fame Cisco Employee

TCL - Clear AUX line

Yes, you can add to that Tcl policy provided you follow EEM Tcl semantics.

The registration command must only include the policy name.  You must first define the policy directory then make sure the policy exists in that directory.  For example:

event manager directory user policy flash:

Highlighted
Cisco Employee

TCL - Clear AUX line

In addition to what Joe has stated, you must also reregister the policy every time you make updates to it.

Highlighted
Beginner

Re: TCL - Clear AUX line

Thanks, guys,

I tried to use it and I got this:

*Jan 30 06:07:21.618: [fh_tty_write_cmd] cmd = clear line aux 0, cmdsize = 16

*Jan 30 06:07:21.618: [fh_sys_reqinfo_routername_cmd]

*Jan 30 06:07:21.630: [fh_tty_prompt_cmd]

*Jan 30 06:07:21.630: [fh_tty_read_cmd]

*Jan 30 06:07:21.630: [fh_tty_read_cmd] size= 9

*Jan 30 06:07:21.730: [fh_tty_read_cmd]

Lots of these two below:

*Jan 30 06:07:21.730: [fh_tty_read_cmd] read not ready

*Jan 30 06:07:21.830: [fh_tty_read_cmd]

and then:

*Jan 30 06:07:40.762: fh_tcl_esi_close: fd=0

*Jan 30 06:07:40.762: fh_tcl_esi_close: fd=1

*Jan 30 06:07:40.762: %HA_EM-6-LOG: teste.tcl: Process Forced Exit

*Jan 30 06:07:40.762: %HA_EM-6-LOG: teste.tcl:     while executing

*Jan 30 06:07:40.762: %HA_EM-6-LOG: teste.tcl: "error $_cli_result $errorInfo"

*Jan 30 06:07:40.762: %HA_EM-6-LOG: teste.tcl:     invoked from within

*Jan 30 06:07:40.762: %HA_EM-6-LOG: teste.tcl: "$slave eval $Contents"

*Jan 30 06:07:40.762: %HA_EM-6-LOG: teste.tcl:     (procedure "eval_script" line 7)

*Jan 30 06:07:40.762: %HA_EM-6-LOG: teste.tcl:     invoked from within

*Jan 30 06:07:40.762: %HA_EM-6-LOG: teste.tcl: "eval_script slave $scriptname"

*Jan 30 06:07:40.762: %HA_EM-6-LOG: teste.tcl:     invoked from within

*Jan 30 06:07:40.762: %HA_EM-6-LOG: teste.tcl: "if {$security_level == 1} {       #untrusted script

*Jan 30 06:07:40.762: %HA_EM-6-LOG: teste.tcl:      interp create -safe slave

*Jan 30 06:07:40.762: %HA_EM-6-LOG: teste.tcl:      interp share {} stdin slave

*Jan 30 06:07:40.762: %HA_EM-6-LOG: teste.tcl:      interp share {} stdout slave

*Jan 30 06:07:40.762: %HA_EM-6-LOG: teste.tcl: ..."

*Jan 30 06:07:40.762: %HA_EM-6-LOG: teste.tcl:     (file "system:/lib/tcl/base.tcl" line 50)

*Jan 30 06:07:40.762: %HA_EM-6-LOG: teste.tcl: Tcl policy execute failed: Process Forced Exit

*Jan 30 06:07:40.762: %HA_EM-6-LOG: teste.tcl: Tcl policy execute failed: Process Forced Exit

*Jan 30 06:07:40.766: fh_tcl_esi_close: fd=2

*Jan 30 06:07:40.766: fh_tcl_assoc_data_delproc: freeing tctx=63A53610

These are results of "debug event manager policydir" and "debug event manager tcl commands".

My original code is:

event manager applet Dial_Test

event none

action 1.0 policy teste.tcl

Suggestions?

Thank you!

Highlighted
Hall of Fame Cisco Employee

Re: TCL - Clear AUX line

Sorry, try this instead:

::cisco::eem::event_register_none 

namespace import ::cisco::eem::*
namespace import ::cisco::lib::*

array set arr_einfo [event_reqinfo]


if [catch {cli_open} result] {
    error $result $errorInfo
} else {
    array set cli1 $result
}

if [catch {cli_exec $cli1(fd) "enable"} _cli_result] {
    error $_cli_result $errorInfo
}

if [catch {cli_write $cli1(fd) "clear line aux 0"} _cli_result] {
    error $_cli_result $errorInfo
}

if [catch {cli_read_pattern $cli1(fd) "confirm"} result] {
    error $result $errorInfo

}

if [catch {cli_exec $cli1(fd) "y"} _cli_result] {
    error $_cli_result $errorInfo
}


# Close open cli before exit.
catch {cli_close $cli1(fd) $cli1(tty_id)} result

View solution in original post

Highlighted
Beginner

Re: TCL - Clear AUX line

Joseph,

Thank you and sorry for insisting with this.  I googled and I found nothing but my own post in this forum.  I did what you suggested, but I got the same result.

Regards

Highlighted
Hall of Fame Cisco Employee

Re: TCL - Clear AUX line

Provided you used my new script, and you re-registered it as Mike mentioned, the cline should clear (or at the very least you should see some different debugging output).

Highlighted
Beginner

Re: TCL - Clear AUX line

I see.

Let's check if I'm doing something wrong.  I did this:

copy tftp flash (and then I recorded the text file with the name as teste.tcl).

event manager directory user policy flash:

event manager policy teste.tcl type user

event manager applet Dial_Test

event none

action 1.0 policy teste.tcl

Finally:  event manager run Dial_Test

Is that ok?

Highlighted
Hall of Fame Cisco Employee

Re: TCL - Clear AUX line

You're missing one step:

no event manager policy teste.tcl

Then register it again.  That will trigger a reload of the policy.  I don't know why you're using an applet, though.  You could just do:

event manager run teste.tcl

Highlighted
Cisco Employee

Re: TCL - Clear AUX line

Try this:

Router(config)#event manager directory user policy flash:

Router(config)#no event manager policy teste.tcl

Router(config)#event manager policy teste.tcl

Router(config)#end

Router#debug event manager tcl cli_library

Debug EEM Tcl CLI library debugging is on

Router#event manager run teste.tcl

Router#

*Oct 25 20:22:09.108: %HA_EM-6-LOG: teste.tcl : DEBUG(cli_lib) : CTL : cli_open called.

*Oct 25 20:22:09.227: %HA_EM-6-LOG: teste.tcl : DEBUG(cli_lib) : OUT : Router>

*Oct 25 20:22:09.283: %HA_EM-6-LOG: teste.tcl : DEBUG(cli_lib) : IN  : Router>enable

*Oct 25 20:22:09.511: %HA_EM-6-LOG: teste.tcl : DEBUG(cli_lib) : OUT : Router#

*Oct 25 20:22:09.511: %HA_EM-6-LOG: teste.tcl : DEBUG(cli_lib) : IN  : Router#clear line aux 0

*Oct 25 20:22:09.715: %HA_EM-6-LOG: teste.tcl : DEBUG(cli_lib) : OUT : [confirm]

*Oct 25 20:22:09.715: %HA_EM-6-LOG: teste.tcl : DEBUG(cli_lib) : IN  : y

*Oct 25 20:22:09.936: %HA_EM-6-LOG: teste.tcl : DEBUG(cli_lib) : OUT : y [OK]

*Oct 25 20:22:09.936:

Router#%HA_EM-6-LOG: teste.tcl : DEBUG(cli_lib) : OUT : Router#

*Oct 25 20:22:09.936: %HA_EM-6-LOG: teste.tcl : DEBUG(cli_lib) : OUT : Router#

*Oct 25 20:22:09.936: %HA_EM-6-LOG: teste.tcl : DEBUG(cli_lib) : CTL : cli_close called.

Mike

Message was edited by: Michael Timm to add the 'no event manager policy' and quote the router output.

Highlighted
Beginner

Re: TCL - Clear AUX line

Thanks, guys,

It is ok now.  Could you tell me if I can use "after" keyword inside my script with a code like this:

set i 0

while {$i < 3} {

   "clearing of AUX 0"

   after 3000 incr i

}

The goal is to "sleep" for about 3 seconds.

Regards

Highlighted
Hall of Fame Cisco Employee

Re: TCL - Clear AUX line

Sure.  You can use most Tcl 8.3.4 constructs within your EEM script.  Though I think you want:

set i 0

while { $i < 3 } {

    "clearing of AUX 0"

    after 3000

    incr i

}

Highlighted
Cisco Employee

Re: TCL - Clear AUX line

Yes you can.  The restricted commands are documented here:

http://www.cisco.com/en/US/docs/ios/12_3t/12_3t14/feature/guide/w_eempol.html#wp1053515

If you do use after, you may need to increase the maxrun (i.e. how long the policy is allowed to run) beyond the default of 20 seconds.  It all depends on how long your script is expected to run.  To do this you would need to update the event specification in the script itself:

::cisco::eem::event_register_none maxrun 60

Mike

CreatePlease to create content
Content for Community-Ad