cancel
Showing results for 
Search instead for 
Did you mean: 

Python SSH script to log into Extreme switch, run command and save output

Python SSH script to log into Extreme switch, run command and save output

Marvell_Kay
New Contributor II
I have been trying to write a python script that logins to Extreme switch via SSH2, runs commands and shows output. I looked at Extreme's github page but can't seem to find it. Is there a example script that someone can share that login and runs commands. I also heard there is a better way to screen scrap Extreme.

Thanks
Damon
8 REPLIES 8

tknv
Extreme Employee
I think using netmiko is easy for python SSH scripting.
Very simple example:
from netmiko import ConnectHandler extrm_X460 = { 'device_type': 'extreme', 'ip': '172.16.10.2', 'username': 'admin', 'password': 'verysecret', 'port' : 12322, # optional, defaults to 22 } net_connect = ConnectHandler(**extrm_X460) output = net_connect.send_command('show switch') print(output)

Norbert_Elitze1
New Contributor
or something like:
#with SSH login without password and authentication keys enabled
import subprocess
try:
out = subprocess.check_output(['printf "show config\n" | ssh -o ForwardX11=no -T admin@10.0.0.1'], shell=True)
except subprocess.CalledProcessError as e:
out = e.output
print out
exit(1)
print "Switch output: %s\n" % out

Ludovico_Steven
Extreme Employee
Also add a last line with:
main()But argparse needs to be imported from somewhere..

OscarK
Extreme Employee
Yes, the script I provided only connects to a switch and exits, to print something you need to add more.
Just before xos.exit() enter lines for commands like:
print xos.cmd("show vlan")

GTM-P2G8KFN