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,