Create dedicated file output of each netmiko send commands (commands in text file)How do I create a Java string from the contents of a file?Why should text files end with a newline?How to create an empty file at the command line in Windows?Create a file in memory for user to download, not through serverRunning shell command and capturing the outputPython Print String To Text FileHow to read a text file into a string variable and strip newlines?How do I find all files containing specific text on Linux?Save output in multiple text filesHow to create dedicated file of each for loop if/else output of Netmiko access

What Brexit solution does the DUP want?

Why did the Germans forbid the possession of pet pigeons in Rostov-on-Don in 1941?

Why can't I see bouncing of a switch on an oscilloscope?

declaring a variable twice in IIFE

Is Social Media Science Fiction?

Draw simple lines in Inkscape

How is it possible for user's password to be changed after storage was encrypted? (on OS X, Android)

How is the claim "I am in New York only if I am in America" the same as "If I am in New York, then I am in America?

My colleague's body is amazing

"which" command doesn't work / path of Safari?

What is the offset in a seaplane's hull?

Why is an old chain unsafe?

Is there really no realistic way for a skeleton monster to move around without magic?

How can the DM most effectively choose 1 out of an odd number of players to be targeted by an attack or effect?

Why has Russell's definition of numbers using equivalence classes been finally abandoned? ( If it has actually been abandoned).

Can an x86 CPU running in real mode be considered to be basically an 8086 CPU?

whey we use polarized capacitor?

How to report a triplet of septets in NMR tabulation?

Extreme, but not acceptable situation and I can't start the work tomorrow morning

TGV timetables / schedules?

Calculus Optimization - Point on graph closest to given point

Can I interfere when another PC is about to be attacked?

What would happen to a modern skyscraper if it rains micro blackholes?

How do I create uniquely male characters?



Create dedicated file output of each netmiko send commands (commands in text file)


How do I create a Java string from the contents of a file?Why should text files end with a newline?How to create an empty file at the command line in Windows?Create a file in memory for user to download, not through serverRunning shell command and capturing the outputPython Print String To Text FileHow to read a text file into a string variable and strip newlines?How do I find all files containing specific text on Linux?Save output in multiple text filesHow to create dedicated file of each for loop if/else output of Netmiko access






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















Before this i adapt method below to save dedicated file for each command but this is troublesome when more and more commands to use and every time have to modified this code.



if device['device_type'] == "cisco_ios" :
file=open('show_version' + '-' + device['ip']+".txt","a")
file.write(connection.send_command('show version'))
file.close()
file=open('show_arp' + '-' + device['ip']+".txt","a")
file.write(connection.send_command('show arp'))
file.close()


The above method not efficient anymore when more commands to use..Thus..i want to create list of commands in text file and send command read from the file and separate each output of each command line (commands.txt) to its own file with unique name (command name as the file name). I have modified the code below but it save all the commands output onto single file.



The code below generate all the output in a single file still not able to make it multiple files.



with open("commands.txt") as cmd_file:
commands = cmd_file.readlines()

for device in devices['device']:
try:
print('Connecting to device:', device['ip'])
connection = netmiko.ConnectHandler(**device)
if device['device_type'] == "cisco_ios" :
filename = connection.base_prompt + '-' + device['ip'] + '.txt'
with open(filename, 'w') as out_file:
for command in commands:
out_file.write(connection.send_command(command))
connection.disconnect()
except netmiko_exceptions as e:
print('Failed to ', device['ip'], e)


The commands.txt file content cisco commands like
show version,
show interface,
show chassic



In this case... final.. 3 files with name of showversion.txt, showinterface.txt and showchassic.txt will be generated.



Please advise me further. Thank you.










share|improve this question




























    0















    Before this i adapt method below to save dedicated file for each command but this is troublesome when more and more commands to use and every time have to modified this code.



    if device['device_type'] == "cisco_ios" :
    file=open('show_version' + '-' + device['ip']+".txt","a")
    file.write(connection.send_command('show version'))
    file.close()
    file=open('show_arp' + '-' + device['ip']+".txt","a")
    file.write(connection.send_command('show arp'))
    file.close()


    The above method not efficient anymore when more commands to use..Thus..i want to create list of commands in text file and send command read from the file and separate each output of each command line (commands.txt) to its own file with unique name (command name as the file name). I have modified the code below but it save all the commands output onto single file.



    The code below generate all the output in a single file still not able to make it multiple files.



    with open("commands.txt") as cmd_file:
    commands = cmd_file.readlines()

    for device in devices['device']:
    try:
    print('Connecting to device:', device['ip'])
    connection = netmiko.ConnectHandler(**device)
    if device['device_type'] == "cisco_ios" :
    filename = connection.base_prompt + '-' + device['ip'] + '.txt'
    with open(filename, 'w') as out_file:
    for command in commands:
    out_file.write(connection.send_command(command))
    connection.disconnect()
    except netmiko_exceptions as e:
    print('Failed to ', device['ip'], e)


    The commands.txt file content cisco commands like
    show version,
    show interface,
    show chassic



    In this case... final.. 3 files with name of showversion.txt, showinterface.txt and showchassic.txt will be generated.



    Please advise me further. Thank you.










    share|improve this question
























      0












      0








      0








      Before this i adapt method below to save dedicated file for each command but this is troublesome when more and more commands to use and every time have to modified this code.



      if device['device_type'] == "cisco_ios" :
      file=open('show_version' + '-' + device['ip']+".txt","a")
      file.write(connection.send_command('show version'))
      file.close()
      file=open('show_arp' + '-' + device['ip']+".txt","a")
      file.write(connection.send_command('show arp'))
      file.close()


      The above method not efficient anymore when more commands to use..Thus..i want to create list of commands in text file and send command read from the file and separate each output of each command line (commands.txt) to its own file with unique name (command name as the file name). I have modified the code below but it save all the commands output onto single file.



      The code below generate all the output in a single file still not able to make it multiple files.



      with open("commands.txt") as cmd_file:
      commands = cmd_file.readlines()

      for device in devices['device']:
      try:
      print('Connecting to device:', device['ip'])
      connection = netmiko.ConnectHandler(**device)
      if device['device_type'] == "cisco_ios" :
      filename = connection.base_prompt + '-' + device['ip'] + '.txt'
      with open(filename, 'w') as out_file:
      for command in commands:
      out_file.write(connection.send_command(command))
      connection.disconnect()
      except netmiko_exceptions as e:
      print('Failed to ', device['ip'], e)


      The commands.txt file content cisco commands like
      show version,
      show interface,
      show chassic



      In this case... final.. 3 files with name of showversion.txt, showinterface.txt and showchassic.txt will be generated.



      Please advise me further. Thank you.










      share|improve this question














      Before this i adapt method below to save dedicated file for each command but this is troublesome when more and more commands to use and every time have to modified this code.



      if device['device_type'] == "cisco_ios" :
      file=open('show_version' + '-' + device['ip']+".txt","a")
      file.write(connection.send_command('show version'))
      file.close()
      file=open('show_arp' + '-' + device['ip']+".txt","a")
      file.write(connection.send_command('show arp'))
      file.close()


      The above method not efficient anymore when more commands to use..Thus..i want to create list of commands in text file and send command read from the file and separate each output of each command line (commands.txt) to its own file with unique name (command name as the file name). I have modified the code below but it save all the commands output onto single file.



      The code below generate all the output in a single file still not able to make it multiple files.



      with open("commands.txt") as cmd_file:
      commands = cmd_file.readlines()

      for device in devices['device']:
      try:
      print('Connecting to device:', device['ip'])
      connection = netmiko.ConnectHandler(**device)
      if device['device_type'] == "cisco_ios" :
      filename = connection.base_prompt + '-' + device['ip'] + '.txt'
      with open(filename, 'w') as out_file:
      for command in commands:
      out_file.write(connection.send_command(command))
      connection.disconnect()
      except netmiko_exceptions as e:
      print('Failed to ', device['ip'], e)


      The commands.txt file content cisco commands like
      show version,
      show interface,
      show chassic



      In this case... final.. 3 files with name of showversion.txt, showinterface.txt and showchassic.txt will be generated.



      Please advise me further. Thank you.







      python file text






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 22 at 1:01









      chenoichenoi

      218




      218






















          0






          active

          oldest

          votes












          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55291419%2fcreate-dedicated-file-output-of-each-netmiko-send-commands-commands-in-text-fil%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55291419%2fcreate-dedicated-file-output-of-each-netmiko-send-commands-commands-in-text-fil%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

          Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

          Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript