<?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: Create file with sysName in filename using Python in Scripting</title>
    <link>https://community.extremenetworks.com/t5/scripting/create-file-with-sysname-in-filename-using-python/m-p/93924#M526</link>
    <description>&lt;P&gt;All functions accepting path or file names accept both bytes and string objects, and result in an object of the same type, if a path or file name is returned.&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://community.extremenetworks.com/t5/user/viewprofilepage/user-id/5517"&gt;@dleboeuf&lt;/a&gt;&lt;A href="https://www.mypayments.plus/" target="_self"&gt;MyPaymentsPlus&lt;/A&gt; App wrote:&lt;BR /&gt;&lt;P&gt;Hello all,&lt;/P&gt;&lt;P&gt;I recently started using Netmiko with Python to script out data collection on EXOS/VOSS switches, and I am trying to export the outputs of commands to a file using the switch name as well as the command that was ran. The script is working, but for some reason I can't get the switch name to attach to the filename, it just keeps exporting with the command that was ran and not the hostname. Here is the code below (bold where I am entering the command to send) where I am trying to get it to work. I am sure it is something simple, I am just a noob with Python!&lt;/P&gt;&lt;P&gt;for switch in switches:&lt;BR /&gt;try:&lt;BR /&gt;net_connect = ConnectHandler(device_type=values[3], ip=switch, username=values[0], password=values[1])&lt;BR /&gt;except:&lt;BR /&gt;filename = switch + ".txt"&lt;BR /&gt;show = "Can't connect to switch: " + switch&lt;BR /&gt;print(show)&lt;BR /&gt;f = open(filename,'w')&lt;BR /&gt;f.write(show)&lt;BR /&gt;f.close&lt;BR /&gt;next&lt;BR /&gt;if values[3] == "voss":&lt;BR /&gt;switchname = net_connect.send_command("show running-config | in sys-name", max_loops=5000)&lt;BR /&gt;else:&lt;BR /&gt;&lt;STRONG&gt;switchname = net_connect.send_command("show system | in SysName: ", max_loops=5000).split(" ")[1]&lt;/STRONG&gt;&lt;BR /&gt;switchname = switchname.replace("\n","")&lt;BR /&gt;print("Executing "+ values[4] + " on " + switchname)&lt;BR /&gt;show = net_connect.send_command(values[4], max_loops=5000)&lt;BR /&gt;filename = switchname.replace(" ","_") + "-" + values[4].replace(" ", "_") + ".txt"&lt;BR /&gt;f = open(filename,'w')&lt;BR /&gt;f.write(show)&lt;BR /&gt;f.close&lt;BR /&gt;print("File " + filename + " generated with the output")&lt;/P&gt;&lt;P&gt;I tried using ("sho config | in sysName") but that isn't working either, it just uses 'snmp' instead of the sysName. I have it working on Cisco devices using ("show run | i hostname") so not sure where I am going wrong, not sure if the double quotes are throwing it off or what.&lt;/P&gt;&lt;P&gt;I appreciate the help!&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 30 Nov 2022 04:38:36 GMT</pubDate>
    <dc:creator>Oliviasalik</dc:creator>
    <dc:date>2022-11-30T04:38:36Z</dc:date>
    <item>
      <title>Create file with sysName in filename using Python</title>
      <link>https://community.extremenetworks.com/t5/scripting/create-file-with-sysname-in-filename-using-python/m-p/93918#M525</link>
      <description>&lt;P&gt;Hello all,&lt;/P&gt;&lt;P&gt;I recently started using Netmiko with Python to script out data collection on EXOS/VOSS switches, and I am trying to export the outputs of commands to a file using the switch name as well as the command that was ran. The script is working, but for some reason I can't get the switch name to attach to the filename, it just keeps exporting with the command that was ran and not the hostname. Here is the code below (bold where I am entering the command to send) where I am trying to get it to work. I am sure it is something simple, I am just a noob with Python!&lt;/P&gt;&lt;P&gt;for switch in switches:&lt;BR /&gt;try:&lt;BR /&gt;net_connect = ConnectHandler(device_type=values[3], ip=switch, username=values[0], password=values[1])&lt;BR /&gt;except:&lt;BR /&gt;filename = switch + ".txt"&lt;BR /&gt;show = "Can't connect to switch: " + switch&lt;BR /&gt;print(show)&lt;BR /&gt;f = open(filename,'w')&lt;BR /&gt;f.write(show)&lt;BR /&gt;f.close&lt;BR /&gt;next&lt;BR /&gt;if values[3] == "voss":&lt;BR /&gt;switchname = net_connect.send_command("show running-config | in sys-name", max_loops=5000)&lt;BR /&gt;else:&lt;BR /&gt;&lt;STRONG&gt;switchname = net_connect.send_command("show system | in SysName: ", max_loops=5000).split(" ")[1]&lt;/STRONG&gt;&lt;BR /&gt;switchname = switchname.replace("\n","")&lt;BR /&gt;print("Executing "+ values[4] + " on " + switchname)&lt;BR /&gt;show = net_connect.send_command(values[4], max_loops=5000)&lt;BR /&gt;filename = switchname.replace(" ","_") + "-" + values[4].replace(" ", "_") + ".txt"&lt;BR /&gt;f = open(filename,'w')&lt;BR /&gt;f.write(show)&lt;BR /&gt;f.close&lt;BR /&gt;print("File " + filename + " generated with the output")&lt;/P&gt;&lt;P&gt;I tried using ("sho config | in sysName") but that isn't working either, it just uses 'snmp' instead of the sysName. I have it working on Cisco devices using ("show run | i hostname") so not sure where I am going wrong, not sure if the double quotes are throwing it off or what.&lt;/P&gt;&lt;P&gt;I appreciate the help!&lt;/P&gt;</description>
      <pubDate>Mon, 28 Nov 2022 22:31:05 GMT</pubDate>
      <guid>https://community.extremenetworks.com/t5/scripting/create-file-with-sysname-in-filename-using-python/m-p/93918#M525</guid>
      <dc:creator>dleboeuf</dc:creator>
      <dc:date>2022-11-28T22:31:05Z</dc:date>
    </item>
    <item>
      <title>Re: Create file with sysName in filename using Python</title>
      <link>https://community.extremenetworks.com/t5/scripting/create-file-with-sysname-in-filename-using-python/m-p/93924#M526</link>
      <description>&lt;P&gt;All functions accepting path or file names accept both bytes and string objects, and result in an object of the same type, if a path or file name is returned.&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://community.extremenetworks.com/t5/user/viewprofilepage/user-id/5517"&gt;@dleboeuf&lt;/a&gt;&lt;A href="https://www.mypayments.plus/" target="_self"&gt;MyPaymentsPlus&lt;/A&gt; App wrote:&lt;BR /&gt;&lt;P&gt;Hello all,&lt;/P&gt;&lt;P&gt;I recently started using Netmiko with Python to script out data collection on EXOS/VOSS switches, and I am trying to export the outputs of commands to a file using the switch name as well as the command that was ran. The script is working, but for some reason I can't get the switch name to attach to the filename, it just keeps exporting with the command that was ran and not the hostname. Here is the code below (bold where I am entering the command to send) where I am trying to get it to work. I am sure it is something simple, I am just a noob with Python!&lt;/P&gt;&lt;P&gt;for switch in switches:&lt;BR /&gt;try:&lt;BR /&gt;net_connect = ConnectHandler(device_type=values[3], ip=switch, username=values[0], password=values[1])&lt;BR /&gt;except:&lt;BR /&gt;filename = switch + ".txt"&lt;BR /&gt;show = "Can't connect to switch: " + switch&lt;BR /&gt;print(show)&lt;BR /&gt;f = open(filename,'w')&lt;BR /&gt;f.write(show)&lt;BR /&gt;f.close&lt;BR /&gt;next&lt;BR /&gt;if values[3] == "voss":&lt;BR /&gt;switchname = net_connect.send_command("show running-config | in sys-name", max_loops=5000)&lt;BR /&gt;else:&lt;BR /&gt;&lt;STRONG&gt;switchname = net_connect.send_command("show system | in SysName: ", max_loops=5000).split(" ")[1]&lt;/STRONG&gt;&lt;BR /&gt;switchname = switchname.replace("\n","")&lt;BR /&gt;print("Executing "+ values[4] + " on " + switchname)&lt;BR /&gt;show = net_connect.send_command(values[4], max_loops=5000)&lt;BR /&gt;filename = switchname.replace(" ","_") + "-" + values[4].replace(" ", "_") + ".txt"&lt;BR /&gt;f = open(filename,'w')&lt;BR /&gt;f.write(show)&lt;BR /&gt;f.close&lt;BR /&gt;print("File " + filename + " generated with the output")&lt;/P&gt;&lt;P&gt;I tried using ("sho config | in sysName") but that isn't working either, it just uses 'snmp' instead of the sysName. I have it working on Cisco devices using ("show run | i hostname") so not sure where I am going wrong, not sure if the double quotes are throwing it off or what.&lt;/P&gt;&lt;P&gt;I appreciate the help!&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Nov 2022 04:38:36 GMT</pubDate>
      <guid>https://community.extremenetworks.com/t5/scripting/create-file-with-sysname-in-filename-using-python/m-p/93924#M526</guid>
      <dc:creator>Oliviasalik</dc:creator>
      <dc:date>2022-11-30T04:38:36Z</dc:date>
    </item>
    <item>
      <title>Re: Create file with sysName in filename using Python</title>
      <link>https://community.extremenetworks.com/t5/scripting/create-file-with-sysname-in-filename-using-python/m-p/93953#M527</link>
      <description>&lt;P&gt;The output of the command&lt;/P&gt;&lt;P&gt;show system | in SysName&lt;/P&gt;&lt;P&gt;is splitted like this&lt;/P&gt;&lt;P&gt;['SysName:', '', '', '', '', '', '', '', '', '', 'foo-sysname']&lt;/P&gt;&lt;P&gt;So you should do&lt;/P&gt;&lt;P&gt;.split(" ")[10]&lt;/P&gt;</description>
      <pubDate>Wed, 30 Nov 2022 09:52:03 GMT</pubDate>
      <guid>https://community.extremenetworks.com/t5/scripting/create-file-with-sysname-in-filename-using-python/m-p/93953#M527</guid>
      <dc:creator>AdrianO</dc:creator>
      <dc:date>2022-11-30T09:52:03Z</dc:date>
    </item>
  </channel>
</rss>

