<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic RE: Python SSH script to log into Extreme switch, run command and save output in ExtremeSwitching (EXOS/Switch Engine)</title>
    <link>https://community.extremenetworks.com/t5/extremeswitching-exos-switch/python-ssh-script-to-log-into-extreme-switch-run-command-and/m-p/47583#M12273</link>
    <description>I think using &lt;A href="https://github.com/ktbyers/netmiko" target="_blank" rel="nofollow noreferrer noopener"&gt;netmiko&lt;/A&gt; is easy for python SSH scripting.&lt;BR /&gt;
Very simple example:&lt;BR /&gt;
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)&lt;BR /&gt;</description>
    <pubDate>Tue, 06 Feb 2018 13:10:00 GMT</pubDate>
    <dc:creator>tknv</dc:creator>
    <dc:date>2018-02-06T13:10:00Z</dc:date>
    <item>
      <title>Python SSH script to log into Extreme switch, run command and save output</title>
      <link>https://community.extremenetworks.com/t5/extremeswitching-exos-switch/python-ssh-script-to-log-into-extreme-switch-run-command-and/m-p/47575#M12265</link>
      <description>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.&lt;BR /&gt;
&lt;BR /&gt;
Thanks&lt;BR /&gt;
Damon</description>
      <pubDate>Thu, 14 Dec 2017 06:09:00 GMT</pubDate>
      <guid>https://community.extremenetworks.com/t5/extremeswitching-exos-switch/python-ssh-script-to-log-into-extreme-switch-run-command-and/m-p/47575#M12265</guid>
      <dc:creator>Marvell_Kay</dc:creator>
      <dc:date>2017-12-14T06:09:00Z</dc:date>
    </item>
    <item>
      <title>RE: Python SSH script to log into Extreme switch, run command and save output</title>
      <link>https://community.extremenetworks.com/t5/extremeswitching-exos-switch/python-ssh-script-to-log-into-extreme-switch-run-command-and/m-p/47576#M12266</link>
      <description>If you're just trying to run a command or two, what about using NetSight.    Or if you don't have that you might consider secure crt instead of putty. CRT would allow you to run commands on groups of switches.</description>
      <pubDate>Thu, 14 Dec 2017 07:00:00 GMT</pubDate>
      <guid>https://community.extremenetworks.com/t5/extremeswitching-exos-switch/python-ssh-script-to-log-into-extreme-switch-run-command-and/m-p/47576#M12266</guid>
      <dc:creator>davidj_cogliane</dc:creator>
      <dc:date>2017-12-14T07:00:00Z</dc:date>
    </item>
    <item>
      <title>RE: Python SSH script to log into Extreme switch, run command and save output</title>
      <link>https://community.extremenetworks.com/t5/extremeswitching-exos-switch/python-ssh-script-to-log-into-extreme-switch-run-command-and/m-p/47577#M12267</link>
      <description>I can't use SecureCRT as it will be a web service.  I was looking for just a script to SSH and run commands .. maybe paramiko/pextect?  I could not find any example.&lt;BR /&gt;
&lt;BR /&gt;
I tried something simple like this but it didn't work:&lt;BR /&gt;
&lt;BR /&gt;
&lt;BLOCKQUOTE&gt;import pexpect&lt;BR /&gt;
import sys&lt;BR /&gt;
&lt;BR /&gt;
switch_ip = "10.10.10.1"&lt;BR /&gt;
switch_un = "user"&lt;BR /&gt;
switch_pw = "pass"&lt;BR /&gt;
&lt;BR /&gt;
child = pexpect.spawn('ssh %s@%s' % (switch_un, switch_ip))&lt;BR /&gt;
child.logfile = sys.stdout&lt;BR /&gt;
child.timeout = 4&lt;BR /&gt;
child.expect('Password:')&lt;BR /&gt;
child.sendline(switch_pw)&lt;BR /&gt;
child.expect('#')&lt;/BLOCKQUOTE&gt;</description>
      <pubDate>Thu, 14 Dec 2017 07:10:00 GMT</pubDate>
      <guid>https://community.extremenetworks.com/t5/extremeswitching-exos-switch/python-ssh-script-to-log-into-extreme-switch-run-command-and/m-p/47577#M12267</guid>
      <dc:creator>Marvell_Kay</dc:creator>
      <dc:date>2017-12-14T07:10:00Z</dc:date>
    </item>
    <item>
      <title>RE: Python SSH script to log into Extreme switch, run command and save output</title>
      <link>https://community.extremenetworks.com/t5/extremeswitching-exos-switch/python-ssh-script-to-log-into-extreme-switch-run-command-and/m-p/47578#M12268</link>
      <description>class SSH2EXOS:&lt;BR /&gt;
    def __init__(self, switch, user='admin',password=''):&lt;BR /&gt;
        self.connected = True&lt;BR /&gt;
        self.client = paramiko.SSHClient()&lt;BR /&gt;
        self.client.set_missing_host_key_policy(paramiko.AutoAddPolicy())&lt;BR /&gt;
        self.client.connect(switch,username=user,password=password)&lt;BR /&gt;
        stdin, stdout, stderr = self.client.exec_command("disable clipaging")&lt;BR /&gt;
        stdin.close()&lt;BR /&gt;
&lt;BR /&gt;
    def cmdFast(self,cmd,timeout=30):&lt;BR /&gt;
        stdin, stdout, stderr = self.client.exec_command(cmd)&lt;BR /&gt;
        stdin.close()&lt;BR /&gt;
        return cmd+"\n"+stdout.read()&lt;BR /&gt;
&lt;BR /&gt;
    def exit(self):&lt;BR /&gt;
        self.client.close()&lt;BR /&gt;
        self.connected = False&lt;BR /&gt;
&lt;BR /&gt;
    def exitwithsave(self,save):&lt;BR /&gt;
        if save == "Y":&lt;BR /&gt;
            print "Saving config"&lt;BR /&gt;
            try:&lt;BR /&gt;
                stdin, stdout, stderr = self.client.exec_command('save')&lt;BR /&gt;
                stdin.flush()&lt;BR /&gt;
                print stdout.read()&lt;BR /&gt;
                self.client.close()&lt;BR /&gt;
                self.connected = False&lt;BR /&gt;
            except:&lt;BR /&gt;
                print "except"&lt;BR /&gt;
        self.client.close()&lt;BR /&gt;
        self.connected = False&lt;BR /&gt;
&lt;BR /&gt;
    def isConnected(self):&lt;BR /&gt;
        if self.connected:&lt;BR /&gt;
            return True&lt;BR /&gt;
        else:&lt;BR /&gt;
            return False&lt;BR /&gt;
&lt;BR /&gt;
def main():&lt;BR /&gt;
    parser = argparse.ArgumentParser(description='Connect to switch(es) and delete xsf files')&lt;BR /&gt;
    parser.add_argument("-u", dest="user", default="admin", help="Username")&lt;BR /&gt;
    parser.add_argument("-p", dest="password", default="", help="Password, leave out for none")&lt;BR /&gt;
    parser.add_argument("-s", dest="switch", default=None, help="Switch IP address")&lt;BR /&gt;
    args = parser.parse_args()&lt;BR /&gt;
    &lt;BR /&gt;
    mlagfilters = None&lt;BR /&gt;
    if args.switch:&lt;BR /&gt;
        print "Connecting to :",args.switch&lt;BR /&gt;
        xos = SSH2EXOS(checkIP(args.switch), user=args.user, password=args.password)&lt;BR /&gt;
        if xos.isConnected():&lt;BR /&gt;
            print "Connected."&lt;BR /&gt;
            info = xos.cmdFast("show switch")&lt;BR /&gt;
            for line in info.splitlines():&lt;BR /&gt;
                m = re.search(r'SysName:\s+(\S+)',line)&lt;BR /&gt;
                if m:&lt;BR /&gt;
                    switchname = m.group(1)&lt;BR /&gt;
            xos.exit()&lt;BR /&gt;
&lt;BR /&gt;</description>
      <pubDate>Thu, 14 Dec 2017 14:33:00 GMT</pubDate>
      <guid>https://community.extremenetworks.com/t5/extremeswitching-exos-switch/python-ssh-script-to-log-into-extreme-switch-run-command-and/m-p/47578#M12268</guid>
      <dc:creator>OscarK</dc:creator>
      <dc:date>2017-12-14T14:33:00Z</dc:date>
    </item>
    <item>
      <title>RE: Python SSH script to log into Extreme switch, run command and save output</title>
      <link>https://community.extremenetworks.com/t5/extremeswitching-exos-switch/python-ssh-script-to-log-into-extreme-switch-run-command-and/m-p/47579#M12269</link>
      <description>Thanks!!!  I will look into JSONRPC but since we have mixture of codes in out env I don't think it is going to work.&lt;BR /&gt;
&lt;BR /&gt;
I tried the second code but when i run it on by Linux machine, it shows nothing.  It does run without giving me any errors but no output.  I have a test device with user "&lt;B&gt;user12&lt;/B&gt;" and password "&lt;B&gt;1password2&lt;/B&gt;" with ip "&lt;B&gt;10.10.10.1&lt;/B&gt;".  Here is how I edited the code.  Can you please check and see if I missed something.  I am not familiar with classes.&lt;BR /&gt;
&lt;BR /&gt;
I also added a print in main and I don't see that either.&lt;BR /&gt;
&lt;BR /&gt;
class SSH2EXOS:&lt;BR /&gt;
    def __init__(self, switch, user='&lt;B&gt;user12&lt;/B&gt;',password='&lt;B&gt;1password2&lt;/B&gt;'):&lt;BR /&gt;
        self.connected = True&lt;BR /&gt;
        self.client = paramiko.SSHClient()&lt;BR /&gt;
        self.client.set_missing_host_key_policy(paramiko.AutoAddPolicy())&lt;BR /&gt;
        self.client.connect(switch,username=user,password=password)&lt;BR /&gt;
        stdin, stdout, stderr = self.client.exec_command("disable clipaging")&lt;BR /&gt;
        stdin.close()&lt;BR /&gt;
    def cmdFast(self,cmd,timeout=30):&lt;BR /&gt;
        stdin, stdout, stderr = self.client.exec_command(cmd)&lt;BR /&gt;
        stdin.close()&lt;BR /&gt;
        return cmd+"\n"+stdout.read()&lt;BR /&gt;
    def exit(self):&lt;BR /&gt;
        self.client.close()&lt;BR /&gt;
        self.connected = False&lt;BR /&gt;
    def exitwithsave(self,save):&lt;BR /&gt;
        if save == "Y":&lt;BR /&gt;
            print "Saving config"&lt;BR /&gt;
            try:&lt;BR /&gt;
                stdin, stdout, stderr = self.client.exec_command('save')&lt;BR /&gt;
                stdin.flush()&lt;BR /&gt;
                print stdout.read()&lt;BR /&gt;
                self.client.close()&lt;BR /&gt;
                self.connected = False&lt;BR /&gt;
            except:&lt;BR /&gt;
                print "except"&lt;BR /&gt;
        self.client.close()&lt;BR /&gt;
        self.connected = False&lt;BR /&gt;
&lt;BR /&gt;
    def isConnected(self):&lt;BR /&gt;
        if self.connected:&lt;BR /&gt;
            return True&lt;BR /&gt;
        else:&lt;BR /&gt;
            return False&lt;BR /&gt;
def main():    &lt;B&gt; print "Main"&lt;/B&gt;&lt;BR /&gt;
    parser = argparse.ArgumentParser(description='Connect to switch(es) and delete xsf files')&lt;BR /&gt;
    parser.add_argument("-u", dest="user", default="&lt;B&gt;user12&lt;/B&gt;", help="Username")&lt;BR /&gt;
    parser.add_argument("-p", dest="password", default="&lt;B&gt;1password2&lt;/B&gt;", help="Password, leave out for none")    parser.add_argument("-s", dest="switch", default=None, help="&lt;B&gt;10.10.10.1&lt;/B&gt;")&lt;BR /&gt;
    args = parser.parse_args() &lt;BR /&gt;
    mlagfilters = None&lt;BR /&gt;
    if args.switch:&lt;BR /&gt;
        print "Connecting to :",args.switch&lt;BR /&gt;
        xos = SSH2EXOS(checkIP(args.switch), user=args.user, password=args.password)&lt;BR /&gt;
        if xos.isConnected():&lt;BR /&gt;
            print "Connected."&lt;BR /&gt;
            info = xos.cmdFast("show switch")&lt;BR /&gt;
            for line in info.splitlines():&lt;BR /&gt;
                m = re.search(r'SysName:\s+(\S+)',line)&lt;BR /&gt;
                if m:&lt;BR /&gt;
                    switchname = m.group(1)&lt;BR /&gt;
            xos.exit()</description>
      <pubDate>Fri, 15 Dec 2017 00:53:00 GMT</pubDate>
      <guid>https://community.extremenetworks.com/t5/extremeswitching-exos-switch/python-ssh-script-to-log-into-extreme-switch-run-command-and/m-p/47579#M12269</guid>
      <dc:creator>Marvell_Kay</dc:creator>
      <dc:date>2017-12-15T00:53:00Z</dc:date>
    </item>
    <item>
      <title>RE: Python SSH script to log into Extreme switch, run command and save output</title>
      <link>https://community.extremenetworks.com/t5/extremeswitching-exos-switch/python-ssh-script-to-log-into-extreme-switch-run-command-and/m-p/47580#M12270</link>
      <description>Yes, the script I provided only connects to a switch and exits, to print something you need to add more.&lt;BR /&gt;
Just before xos.exit() enter lines for commands like:&lt;BR /&gt;
print xos.cmd("show vlan")&lt;BR /&gt;
&lt;BR /&gt;</description>
      <pubDate>Mon, 18 Dec 2017 14:50:00 GMT</pubDate>
      <guid>https://community.extremenetworks.com/t5/extremeswitching-exos-switch/python-ssh-script-to-log-into-extreme-switch-run-command-and/m-p/47580#M12270</guid>
      <dc:creator>OscarK</dc:creator>
      <dc:date>2017-12-18T14:50:00Z</dc:date>
    </item>
    <item>
      <title>RE: Python SSH script to log into Extreme switch, run command and save output</title>
      <link>https://community.extremenetworks.com/t5/extremeswitching-exos-switch/python-ssh-script-to-log-into-extreme-switch-run-command-and/m-p/47581#M12271</link>
      <description>Also add a last line with:&lt;BR /&gt;
main()But argparse needs to be imported from somewhere..&lt;BR /&gt;</description>
      <pubDate>Tue, 16 Jan 2018 21:21:00 GMT</pubDate>
      <guid>https://community.extremenetworks.com/t5/extremeswitching-exos-switch/python-ssh-script-to-log-into-extreme-switch-run-command-and/m-p/47581#M12271</guid>
      <dc:creator>Ludovico_Steven</dc:creator>
      <dc:date>2018-01-16T21:21:00Z</dc:date>
    </item>
    <item>
      <title>RE: Python SSH script to log into Extreme switch, run command and save output</title>
      <link>https://community.extremenetworks.com/t5/extremeswitching-exos-switch/python-ssh-script-to-log-into-extreme-switch-run-command-and/m-p/47582#M12272</link>
      <description>or something like:&lt;BR /&gt;
#with SSH login without password and authentication keys enabled&lt;BR /&gt;
import subprocess&lt;BR /&gt;
try:&lt;BR /&gt;
  out = subprocess.check_output(['printf "show config\n" | ssh -o ForwardX11=no -T &lt;A href="https://mailto:admin@10.0.0.1" target="_blank" rel="nofollow noreferrer noopener"&gt;admin@10.0.0.1&lt;/A&gt;'], shell=True)&lt;BR /&gt;
except subprocess.CalledProcessError as e:&lt;BR /&gt;
  out = e.output&lt;BR /&gt;
  print out&lt;BR /&gt;
  exit(1)&lt;BR /&gt;
print "Switch output: %s\n" %  out</description>
      <pubDate>Thu, 18 Jan 2018 01:02:00 GMT</pubDate>
      <guid>https://community.extremenetworks.com/t5/extremeswitching-exos-switch/python-ssh-script-to-log-into-extreme-switch-run-command-and/m-p/47582#M12272</guid>
      <dc:creator>Norbert_Elitze1</dc:creator>
      <dc:date>2018-01-18T01:02:00Z</dc:date>
    </item>
    <item>
      <title>RE: Python SSH script to log into Extreme switch, run command and save output</title>
      <link>https://community.extremenetworks.com/t5/extremeswitching-exos-switch/python-ssh-script-to-log-into-extreme-switch-run-command-and/m-p/47583#M12273</link>
      <description>I think using &lt;A href="https://github.com/ktbyers/netmiko" target="_blank" rel="nofollow noreferrer noopener"&gt;netmiko&lt;/A&gt; is easy for python SSH scripting.&lt;BR /&gt;
Very simple example:&lt;BR /&gt;
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)&lt;BR /&gt;</description>
      <pubDate>Tue, 06 Feb 2018 13:10:00 GMT</pubDate>
      <guid>https://community.extremenetworks.com/t5/extremeswitching-exos-switch/python-ssh-script-to-log-into-extreme-switch-run-command-and/m-p/47583#M12273</guid>
      <dc:creator>tknv</dc:creator>
      <dc:date>2018-02-06T13:10:00Z</dc:date>
    </item>
  </channel>
</rss>

