<?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 Can I save the results of a script to file? in ExtremeCloud IQ- Site Engine Management Center</title>
    <link>https://community.extremenetworks.com/t5/extremecloud-iq-site-engine/can-i-save-the-results-of-a-script-to-file/m-p/27724#M2556</link>
    <description>I need to login to a switch, run a 'show' command, then save the output to a file. I need to do this for 30+ switches, and would preferably like to save the output of each switch's show command to a filename matching it's hostname (SwitchA output to switcha.txt).&lt;BR /&gt;
I know how to write a script to run the show command, but I don't know how to save it to a file.&lt;BR /&gt;
Any ideas?&lt;BR /&gt;
Thank you!</description>
    <pubDate>Fri, 14 Jul 2017 04:38:00 GMT</pubDate>
    <dc:creator>Martin_Shadbolt</dc:creator>
    <dc:date>2017-07-14T04:38:00Z</dc:date>
    <item>
      <title>Can I save the results of a script to file?</title>
      <link>https://community.extremenetworks.com/t5/extremecloud-iq-site-engine/can-i-save-the-results-of-a-script-to-file/m-p/27724#M2556</link>
      <description>I need to login to a switch, run a 'show' command, then save the output to a file. I need to do this for 30+ switches, and would preferably like to save the output of each switch's show command to a filename matching it's hostname (SwitchA output to switcha.txt).&lt;BR /&gt;
I know how to write a script to run the show command, but I don't know how to save it to a file.&lt;BR /&gt;
Any ideas?&lt;BR /&gt;
Thank you!</description>
      <pubDate>Fri, 14 Jul 2017 04:38:00 GMT</pubDate>
      <guid>https://community.extremenetworks.com/t5/extremecloud-iq-site-engine/can-i-save-the-results-of-a-script-to-file/m-p/27724#M2556</guid>
      <dc:creator>Martin_Shadbolt</dc:creator>
      <dc:date>2017-07-14T04:38:00Z</dc:date>
    </item>
    <item>
      <title>RE: Can I save the results of a script to file?</title>
      <link>https://community.extremenetworks.com/t5/extremecloud-iq-site-engine/can-i-save-the-results-of-a-script-to-file/m-p/27725#M2557</link>
      <description>If you run it as a task you can have it email you the results.</description>
      <pubDate>Fri, 14 Jul 2017 05:04:00 GMT</pubDate>
      <guid>https://community.extremenetworks.com/t5/extremecloud-iq-site-engine/can-i-save-the-results-of-a-script-to-file/m-p/27725#M2557</guid>
      <dc:creator>davidj_cogliane</dc:creator>
      <dc:date>2017-07-14T05:04:00Z</dc:date>
    </item>
    <item>
      <title>RE: Can I save the results of a script to file?</title>
      <link>https://community.extremenetworks.com/t5/extremecloud-iq-site-engine/can-i-save-the-results-of-a-script-to-file/m-p/27726#M2558</link>
      <description>You could save the configuration as a script (give it a name) then copy the files from your switch stack, say tftp off.   It saves it as an .xsf file if that would work for you.  Then you could copy the file off the switch stack to a centralized location.  If you have netsight you can automate backups of your stacks.&lt;BR /&gt;
&lt;BR /&gt;
Slot-1 SwitchA # save configuration as-script SwitchA&lt;BR /&gt;
Do you want to save configuration to script SwitchA.xsf? (y/N) Yes&lt;BR /&gt;
Saving configuration to script SwitchA.xsf on master .... done!&lt;BR /&gt;
Synchronizing script to backup ... done!&lt;BR /&gt;
Saving script on Standbys (Slots: 3,4).&lt;BR /&gt;
&lt;BR /&gt;
Script saved on Standby (Slot-4): done!&lt;BR /&gt;
Script saved on Standby (Slot-3): done!&lt;BR /&gt;
&lt;BR /&gt;</description>
      <pubDate>Mon, 17 Jul 2017 17:55:00 GMT</pubDate>
      <guid>https://community.extremenetworks.com/t5/extremecloud-iq-site-engine/can-i-save-the-results-of-a-script-to-file/m-p/27726#M2558</guid>
      <dc:creator>Sarah_Seidl</dc:creator>
      <dc:date>2017-07-17T17:55:00Z</dc:date>
    </item>
    <item>
      <title>RE: Can I save the results of a script to file?</title>
      <link>https://community.extremenetworks.com/t5/extremecloud-iq-site-engine/can-i-save-the-results-of-a-script-to-file/m-p/27727#M2559</link>
      <description>Depending on the EXOS release, you may have python available. A python script can do this for you.</description>
      <pubDate>Mon, 17 Jul 2017 19:46:00 GMT</pubDate>
      <guid>https://community.extremenetworks.com/t5/extremecloud-iq-site-engine/can-i-save-the-results-of-a-script-to-file/m-p/27727#M2559</guid>
      <dc:creator>Dave_Hammers</dc:creator>
      <dc:date>2017-07-17T19:46:00Z</dc:date>
    </item>
    <item>
      <title>RE: Can I save the results of a script to file?</title>
      <link>https://community.extremenetworks.com/t5/extremecloud-iq-site-engine/can-i-save-the-results-of-a-script-to-file/m-p/27728#M2560</link>
      <description>easiest would be using Netsight, create a script and run it on all your switches.&lt;BR /&gt;
&lt;BR /&gt;
Next easiest would be run below python script on a PC that connects to each switch and run the commands you need.&lt;BR /&gt;
#!/usr/bin/env python&lt;BR /&gt;
# This script connect to one or more switches and execute the commands&lt;BR /&gt;
&lt;BR /&gt;
__version__ = '0.80'&lt;BR /&gt;
&lt;BR /&gt;
import telnetlib&lt;BR /&gt;
import re&lt;BR /&gt;
import argparse&lt;BR /&gt;
import sys&lt;BR /&gt;
import paramiko&lt;BR /&gt;
import time&lt;BR /&gt;
&lt;BR /&gt;
class ExosClass:&lt;BR /&gt;
    def __init__(self, host, user='admin',password=''):&lt;BR /&gt;
        self.host=host&lt;BR /&gt;
        self.user=user&lt;BR /&gt;
        self.password=password&lt;BR /&gt;
        self.prompt=re.compile(r'\S+\d+\s[#&amp;gt;]\s')&lt;BR /&gt;
        self.loginprompt=r"login"&lt;BR /&gt;
        self.passwordprompt=r"assword"&lt;BR /&gt;
        self.failedlogin = r"Login incorrect"&lt;BR /&gt;
        self.connected = True&lt;BR /&gt;
        try:&lt;BR /&gt;
            self._tn = telnetlib.Telnet(self.host)&lt;BR /&gt;
            self._tn.set_debuglevel(0)&lt;BR /&gt;
            self._tn.read_until(self.loginprompt,10)&lt;BR /&gt;
            self._tn.write(self.user + "\n")&lt;BR /&gt;
            self._tn.expect([self.passwordprompt],10)&lt;BR /&gt;
            self._tn.write(self.password + "\n")&lt;BR /&gt;
            loginresponse = self._tn.expect([self.prompt,self.failedlogin])&lt;BR /&gt;
            if loginresponse[0] == 1:&lt;BR /&gt;
                print "Login failed"&lt;BR /&gt;
                self.connected = False&lt;BR /&gt;
                self._tn.close()&lt;BR /&gt;
            else:&lt;BR /&gt;
                self._tn.write("disable clipaging\n")&lt;BR /&gt;
                self._tn.expect([self.prompt])&lt;BR /&gt;
        except:&lt;BR /&gt;
            print "Could not connect to switch "+host&lt;BR /&gt;
            self.connected = False&lt;BR /&gt;
&lt;BR /&gt;
    def exit(self):&lt;BR /&gt;
        self._tn.close()&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 cmd(self,cmd,timeout=30):&lt;BR /&gt;
        self._tn.write(cmd + "\n")&lt;BR /&gt;
        s=self._tn.expect([self.prompt],timeout)[2].lstrip(cmd).lstrip('\n\r')&lt;BR /&gt;
        if s.count('\n')&amp;gt;1:&lt;BR /&gt;
            return s[:s.rfind('\n')]&lt;BR /&gt;
        else:&lt;BR /&gt;
            return "OK"&lt;BR /&gt;
&lt;BR /&gt;
    def cmdFast(self,cmd,timeout=30):&lt;BR /&gt;
        self._tn.write(cmd+"\n")&lt;BR /&gt;
        output=""&lt;BR /&gt;
        go = True&lt;BR /&gt;
        while go:&lt;BR /&gt;
            time.sleep(0.5)&lt;BR /&gt;
            newoutput = self._tn.read_very_eager()&lt;BR /&gt;
            if len(newoutput) == 0:&lt;BR /&gt;
                lastline = output.splitlines()[-1]&lt;BR /&gt;
                if re.search(self.prompt,lastline):&lt;BR /&gt;
                    go = False&lt;BR /&gt;
            else:&lt;BR /&gt;
                output += newoutput&lt;BR /&gt;
        return output&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;
            self._tn.write("save\n")&lt;BR /&gt;
            output=""&lt;BR /&gt;
            go = True&lt;BR /&gt;
            try:&lt;BR /&gt;
                while go:&lt;BR /&gt;
                    time.sleep(0.5)&lt;BR /&gt;
                    newoutput = self._tn.read_very_eager()&lt;BR /&gt;
                    if re.search(r'.*(y/N).*',newoutput):&lt;BR /&gt;
                        go = False&lt;BR /&gt;
                        self._tn.write(save+"\n")&lt;BR /&gt;
                go = True&lt;BR /&gt;
                while go:&lt;BR /&gt;
                    time.sleep(0.5)&lt;BR /&gt;
                    newoutput += self._tn.read_very_eager()&lt;BR /&gt;
                    if re.search(r'.*successfully.*',newoutput):&lt;BR /&gt;
                        go = False&lt;BR /&gt;
                print newoutput&lt;BR /&gt;
            except:&lt;BR /&gt;
                print "except"&lt;BR /&gt;
                self._tn.close()&lt;BR /&gt;
&lt;BR /&gt;
        self._tn.close()&lt;BR /&gt;
        self.connected = False&lt;BR /&gt;
&lt;BR /&gt;
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.write(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 checkIP(address):&lt;BR /&gt;
    m = re.search('(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})',address)&lt;BR /&gt;
    if m:&lt;BR /&gt;
        return m.group(1)&lt;BR /&gt;
    else:&lt;BR /&gt;
        return None&lt;BR /&gt;
&lt;BR /&gt;
def main():&lt;BR /&gt;
    parser = argparse.ArgumentParser(description='Connect to switch(es) and run commands')&lt;BR /&gt;
    parser.add_argument("-s", dest="switch", default=None, help="Switch IP")&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("-f", dest="file", default=None, help="File containing switch IP addresses")&lt;BR /&gt;
    parser.add_argument("-c", dest="cmdfile", default=None, help="File containing switch commands")&lt;BR /&gt;
    parser.add_argument("--ssh", dest="SSH", action='store_true', help="Use SSH to access switches instead of telnet")&lt;BR /&gt;
    parser.add_argument("--save", dest="save", action='store_true', default=False, help="Save config on switch")&lt;BR /&gt;
    parser.add_argument("--print", dest="cmdprint", action='store_true', default=False, help="Print commands being executed")&lt;BR /&gt;
    args = parser.parse_args()&lt;BR /&gt;
&lt;BR /&gt;
    switches = []&lt;BR /&gt;
    validInput = True&lt;BR /&gt;
    if args.switch:&lt;BR /&gt;
         if checkIP(args.switch):&lt;BR /&gt;
             switches.append(args.switch)&lt;BR /&gt;
         else:&lt;BR /&gt;
             print "No Valid IP address specified with -s"&lt;BR /&gt;
             validInput = False&lt;BR /&gt;
    elif args.file:&lt;BR /&gt;
         try:&lt;BR /&gt;
             f = open(args.file,'r')&lt;BR /&gt;
             for line in f.read().splitlines():&lt;BR /&gt;
                 switches.append(line)&lt;BR /&gt;
             f.close()&lt;BR /&gt;
         except IOError as e:&lt;BR /&gt;
             print "I/O error({0}): {1}".format(e.errno, e.strerror)&lt;BR /&gt;
         except:&lt;BR /&gt;
             print "Something wrong with opening the switch file"&lt;BR /&gt;
             validInput = False&lt;BR /&gt;
    else:&lt;BR /&gt;
         print "No valid option -s or -f specified"&lt;BR /&gt;
         validInput = False&lt;BR /&gt;
&lt;BR /&gt;
    if args.cmdfile:&lt;BR /&gt;
        f = open(args.cmdfile,'r')&lt;BR /&gt;
        cmds = []&lt;BR /&gt;
        for line in f.read().splitlines():&lt;BR /&gt;
            cmds.append(line)&lt;BR /&gt;
        f.close()&lt;BR /&gt;
    else:&lt;BR /&gt;
        print "No file with commands given"&lt;BR /&gt;
        validInput = False&lt;BR /&gt;
&lt;BR /&gt;
    if args.save:&lt;BR /&gt;
        save = "Y"&lt;BR /&gt;
    else:&lt;BR /&gt;
        save = "N"&lt;BR /&gt;
    if validInput:&lt;BR /&gt;
        for switch in switches:&lt;BR /&gt;
            print "Executing on switch "+switch,&lt;BR /&gt;
            sys.stdout.flush()&lt;BR /&gt;
            if args.SSH:&lt;BR /&gt;
                MySess = SSH2EXOS(switch,args.user,args.password)&lt;BR /&gt;
            else:&lt;BR /&gt;
                MySess = ExosClass(switch,args.user,args.password)&lt;BR /&gt;
&lt;BR /&gt;
            if MySess.isConnected():&lt;BR /&gt;
                print " connected, running commands"&lt;BR /&gt;
                for cmd in cmds:&lt;BR /&gt;
                    if args.cmdprint:&lt;BR /&gt;
                        print cmd +"\n"&lt;BR /&gt;
                    print MySess.cmd(cmd)&lt;BR /&gt;
                MySess.exitwithsave(save)&lt;BR /&gt;
&lt;BR /&gt;
if __name__ == "__main__":&lt;BR /&gt;
    try:&lt;BR /&gt;
        main()&lt;BR /&gt;
    except SystemExit:&lt;BR /&gt;
        pass&lt;BR /&gt;
&lt;BR /&gt;</description>
      <pubDate>Tue, 18 Jul 2017 11:33:00 GMT</pubDate>
      <guid>https://community.extremenetworks.com/t5/extremecloud-iq-site-engine/can-i-save-the-results-of-a-script-to-file/m-p/27728#M2560</guid>
      <dc:creator>OscarK</dc:creator>
      <dc:date>2017-07-18T11:33:00Z</dc:date>
    </item>
    <item>
      <title>RE: Can I save the results of a script to file?</title>
      <link>https://community.extremenetworks.com/t5/extremecloud-iq-site-engine/can-i-save-the-results-of-a-script-to-file/m-p/27729#M2561</link>
      <description>that would be even better using json-rpc, if running 21.1+.&lt;BR /&gt;</description>
      <pubDate>Tue, 18 Jul 2017 11:33:00 GMT</pubDate>
      <guid>https://community.extremenetworks.com/t5/extremecloud-iq-site-engine/can-i-save-the-results-of-a-script-to-file/m-p/27729#M2561</guid>
      <dc:creator>Stephane_Grosj1</dc:creator>
      <dc:date>2017-07-18T11:33:00Z</dc:date>
    </item>
    <item>
      <title>RE: Can I save the results of a script to file?</title>
      <link>https://community.extremenetworks.com/t5/extremecloud-iq-site-engine/can-i-save-the-results-of-a-script-to-file/m-p/27730#M2562</link>
      <description>Well, if you have a GNU/Linux server and switches with a recent version of EXOS you could &lt;A href="https://gtacknowledge.extremenetworks.com/articles/How_To/How-to-configure-user-key-based-authentication-using-the-CLI/" target="_blank" rel="nofollow noreferrer noopener"&gt;add an SSH key&lt;/A&gt; to the switches and use a simple bash script:&lt;BR /&gt;
for S in switch1 switch2 switch3;  do ssh -i &lt;I&gt;the_private_key&lt;/I&gt; "$S" "show ports no-refresh" &amp;gt; "${S}.txt";  doneThanks,&lt;BR /&gt;
Erik</description>
      <pubDate>Tue, 18 Jul 2017 12:29:00 GMT</pubDate>
      <guid>https://community.extremenetworks.com/t5/extremecloud-iq-site-engine/can-i-save-the-results-of-a-script-to-file/m-p/27730#M2562</guid>
      <dc:creator>Erik_Auerswald</dc:creator>
      <dc:date>2017-07-18T12:29:00Z</dc:date>
    </item>
  </channel>
</rss>

