cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1631
Views
0
Helpful
5
Replies

Using EEM to telnet to switches and execute commands

paul-sungard
Level 1
Level 1

Can EEM telnet to other switches.

It doesn't seem to work and when you run debug it drops out at the password for telnet.

I have tried using the "pattern" option to put the telnet password in.  but can't get it to work

All I won't to be able to do is automatically run a few commands on other switches from the core.

Any ideas

5 Replies 5

Xin Cheng
Cisco Employee
Cisco Employee

I can assure you EEM on IOS can initiate telnet session without a hitch, but on IOX, still struggling to find out the workaroud.

 

proc remote_cmd_telnet { remote_host username password prompt_expect clist } {
    # this function will carry out each command contained in the clist on remote host.
    if { [catch {cli_open} result] } {
             PUTS $result
             return 1
        } else {
             array set cliarr $result
        }
    
    #Login to remote router
    
    if { [catch {cli_write $cliarr(fd) "telnet  $remote_host" } result] } {
         PUTS $result
         return 1
    }   

    PUTS $result

#   if { [catch {cli_read_pattern $cliarr(fd) "Username:"} result] } {
#        PUTS error "Failed to read response: '$result'"
#       return 1    
#     }
#   
#
#   PUTS $result
#
    if { [catch {cli_write $cliarr(fd) $username } result] } {
         PUTS $result
         return 1
        }

    PUTS $result

    if { [catch {cli_read_pattern $cliarr(fd) "Password:"} result] } {
        PUTS error "Failed to read response: '$result'"
        return 1    
     }   

    PUTS $result

    if { [catch {cli_write $cliarr(fd) $password } result] } {
         PUTS $result
         return 1
        }

    PUTS $result

    if { [catch {cli_read_pattern $cliarr(fd) "#"} result] } {

 

 

Hi  xincheng

Yes EEM does initiate telnet, I can see that from the debug but doesn't seem to accept the password using pattern.  What you have written looks great but way over my head.  I take it it I could just paste it to the switch and that would create the process remote_cms_telnet.

there is no username required, there is just the vty/telnet password.

All I want to do is run a progam that will telnet to various switches and run a few commands on a selection of ports It was 6 commands using EEM but it doesn't work.

Regards

 

Paul

 

 

Hi Paul,

Please tell me which IOS /IOX version you are running ?

Version 12.2(17r)SX3, RELEASE SOFTWARE (fc1)

Paul,

I believe that IOS is not capable of doing that, like Ivan posted long time ago.

http://blog.ipspace.net/2007/10/you-cannot-start-telnet-session-from.html

If possible, please upgrade to 15.X, which fixed some bugs about eem.

 

Review Cisco Networking for a $25 gift card