Wired Intelligent Edge

last person joined: 16 hours ago 

Bring performance and reliability to your network with the HPE Aruba Networking Core, Aggregation, and Access layer switches. Discuss the latest features and functionality of your switching devices, and find ways to improve security across your network to bring together a mobile-first solution
Expand all | Collapse all

sample ssh login expect (or py3) script for 3800 switch?

This thread has been viewed 1 times
  • 1.  sample ssh login expect (or py3) script for 3800 switch?

    Posted Mar 05, 2019 02:06 PM

    Does anyone have an example script that can log into a 3800 switch and perform a "show vlan" and the log off? 

    I have been working with examples from a google search but no luck. My sample here doesn't send the "show vlan" command correctly and ends in   strange way. Also, it pauses for several seconds at the password prompt and several seconds after the "Press Any Key to Continue" prompt (??).

     

    #!/usr/bin/expect
    #log_user 0
    spawn ssh -l manager 192.168.1.15
    expect "manager@192.168.1.15's password:"
    exp_send "admin"
    expect "Press any key to continue"
    exp_send "\r"
    expect "HP-3800-24G-PoEP-2SFPP#"
    exp_send "show vlans\r"
    expect "HP-3800-24G-PoEP-2SFPP#"

     

    (End of output)

    HP-3800-24G-PoEP-2SFPP# how vlans
    Invalid input: how
    HP-3800-24G-PoEP-2SFPP# ^[[38;147Rroot@server1:~$ ;147R

     

    I would really be grateful if someone could share a WORKING expect (or python3) script that can log in, execute one command and end. I just need a good starting point.

     

    Thank you,



  • 2.  RE: sample ssh login expect (or py3) script for 3800 switch?

    EMPLOYEE
    Posted Mar 05, 2019 03:20 PM

    Greetings!

     

    Have you tried repeating the carriage return immediately after logging in to dismiss the "Press any key to continue" prompt? I've seen it mentioned in at least one other script example that sometimes multiple carriage returns are required to get to the prompt. You might also try sending another character in place of the carriage return to dismiss the prompt.



  • 3.  RE: sample ssh login expect (or py3) script for 3800 switch?

    MVP GURU
    Posted Mar 05, 2019 04:29 PM

    What do no using (REST) API for this ?!