cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
3057
Views
0
Helpful
17
Replies

EEM Applet to send a message to VTY lines

Jason Kopacko
Level 4
Level 4

No matter what I do, I can't seem to get an EEM script to send a message to all VTY lines. I am sure it is something ASCII related, but not sure what the fix is.

I have a script that, for now, collects all currently logged in users as my test, and then sends the info to the VTY lines.

$userline0 = is my variable that holds the usernames

====================================
action 9.22 cli command "enable"
action 9.23 cli command "send vty 1"
action 9.24 cli command "$userline0"
action 9.25 cli command "\032"
action 9.26 cli command "\x0a"
====================================

Any advice as how to proceed?

17 Replies 17

Joe Clarke
Cisco Employee
Cisco Employee
These commands are interactive. Try: event manager applet sendt event none action 1.0 cli command "enable" action 2.0 cli command "send vty 1" pattern "CTRL/C:" action 3.0 cli command "$userline0 \032"

Thanks Joe, I will try it and let you know.

It is kind of working, but I have multiple lines to send.

I can't find what the ASCII code is for carriage return.

Here is my code:


action 9.00 comment "#### Send Message ####"
action 9.01 cli command "enable"
action 9.02 cli command "send *" pattern "CTRL/C:"
action 9.03 cli command "$userline0"
action 9.04 cli command "$userline1 \013"
action 9.05 cli command "$userline2 \013"
action 9.06 cli command "$userline3 \013"
action 9.07 cli command "$userline4 \013"
action 9.98 cli command "\032"
action 9.99 cli command "exit"

You'll need to use the pattern keyword after each line to wait for the next.  It might be easier to put everything in one variable, though.  You can try:

action X cli command "$userline0" pattern ".*"

...

No, that didn't work.

I would love to join each line together but I can't seem to get append to work. I'd want to have the carriage returns in the final variable.

You need to use \012 for NL.  And you need to do it all on one line.  This should work:

action X cli command "$var1\012$var2\032"

Awesome....that worked.

It exposed a problem that I had resovled with if conditionals but those go out the window with this setup.

I guess I need to get back to getting all 5 variables stored in one variable.

I cant seem to append userline0 to userline1.

Not sure what you're trying, but this shoul work:

action X append userline0 $userline1

Here is what I have:

action 9.00 comment "#### Send Message ####"
action 9.01 set message "0"
action 9.10 append message \012
action 9.11 append message userline0\012
action 9.12 append message userline1\012
action 9.13 append message userline2\012
action 9.14 append message userline3\012
action 9.15 append message userline4\012
action 9.19 puts "###########\012 Results \012###########\012 $message"
action 9.99 cli command "exit"

This is the results:

###########
Results
###########
0
userline0
userline1
userline2
userline3
userline4

Looks like it's working to me.  Did you perhaps mean to do:

action 9.11 append message $userline0\012

With or without the "$" it is not appending the value of the variable.

This is working for me on recent IOS:

event manager applet appendt
 event none
 action 1.0 set a "foo"
 action 2.0 set b "bar"
 action 3.0 append a "$b"
 action 4.0 puts "$a"

Output is "foobar"

I just retyped each line, one by one:


action 9.00 comment "#### Send Message ####"
action 9.10 append userline0 "\012"
action 9.11 append userline0 " $userline1\012"
action 9.12 append userline0 " $userline2\012"
action 9.13 append userline0 " $userline3\012"
action 9.14 append userline0 " $userline4\012"
action 9.19 puts "###########\012 Results \012###########\012 $userline0"
action 9.99 cli command "exit"

The results are:

###########
Results
###########
Line:vty(0) | User: ---removed---
Line:vty(1) | User: ---removed---
0
0
0

So now it appears to be working. So I need to build a nested "if" to do the appending only if the var not equal "0".