cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
2908
Views
5
Helpful
2
Replies

EEM/TCL to SSH -l "show command" and ouput to terminal

Dear community,

 

 

Background information and Issue:

IOS menu is used after an initial SSH session to the router. Switch interface status ouput is one of the options in the menu. Currently rsh is used to output this but telnet is required in the vty configuration.

 

The command looks like this: rsh ipaddress /user username show interface status

 

Hardware and software:

Router - C891F-K9 - 15.3(3)M4

Switch - C2960X (does not support EEM!) - 15.0(2a)EX5

 

Possible Solution:

I am looking for an SSH alternative, which is:

ssh -l username ipaddress "show interface status"

 

After SSH to the cisco router (C891F-K9) i'd like to be able to automate:

ssh -l username ipaddress "show interface status"

 

In my situation, the device is a switch (C2960X). When executing above command from the router, the output is shown in the terminal nice and neatly. However a password is prompted and i'd like to automate this process by using EEM (or TCL) but having difficulty in doing so (i have only just started using EEM/TCL).

 

Of course I have been googling first and the topic that comes closest to my situation is: 

https://supportforums.cisco.com/t5/eem-scripting/q-can-you-repeatedly-ssh-from-within-a-tcl-script-to-for-example/td-p/2356174

 

Script and attempts:

 

!

event manager applet ssh

 

event none

 

action 1.0 cli command "ssh -l username ipaddress" pattern "assword:"

action 2.0 cli command "password" pattern "#"

action 3.0 cli command "show int status"

action 4.0 puts "$_cli_result" 

!

end

 

Then test the script using event manager run ssh

However, there is no output. The command is probably fired off but there is no output to the terminal (in this case an SSH session with the router).

 

I have tried "ssh -l username ipaddress `show int status`" or other variants but this does not work and I don't know the proper syntax because of the "quotes" which are needed to create an action and quotes are needed to execute the show command, if that makes sense. 

 

As always, your help is highly appreciated! :)! Any alternatives/suggestions are welcome.

 

Regards,

 

Vincent 

1 Accepted Solution

Accepted Solutions

Joe Clarke
Cisco Employee
Cisco Employee

event manager applet ssh

event none

action 0.5 cli command "enable"

action 1.0 cli command "ssh -l username ipaddress" pattern "assword:"

action 2.0 cli command "password" pattern "#"

action 2.5 cli command "term len 0" pattern "#"

action 2.6 cli command "term width 0" pattern "#"

action 3.0 cli command "show int status" pattern "#"

action 4.0 puts "$_cli_result" 

action 5.0 cli command "exit"

View solution in original post

2 Replies 2

Joe Clarke
Cisco Employee
Cisco Employee

event manager applet ssh

event none

action 0.5 cli command "enable"

action 1.0 cli command "ssh -l username ipaddress" pattern "assword:"

action 2.0 cli command "password" pattern "#"

action 2.5 cli command "term len 0" pattern "#"

action 2.6 cli command "term width 0" pattern "#"

action 3.0 cli command "show int status" pattern "#"

action 4.0 puts "$_cli_result" 

action 5.0 cli command "exit"

Joe - you are the man! My thanks to you.

Review Cisco Networking for a $25 gift card