Back to Browse

Python Tutorial: Learn to Save Cisco command Output to Text file | Regex Parser Part 2

4.9K views
Mar 14, 2021
8:29

#CiscoBackupPython #ParamikoSShbackup #ConfigBackupPython Playlist: Learn to Parse Cisco Configuration using Python RegEx:re Tutorial https://www.youtube.com/playlist?list=PLOocymQm7YWY8Eksax8mjRSWbUijb7W93 Playlist: Python Learning for Network Engineers https://www.youtube.com/watch?v=sG_RiytUA38&list=PLOocymQm7YWakdZkBfCRIC06fv7xQE85N Playlist: Learn to Read Data From CSV Using Python https://www.youtube.com/watch?v=3XoVPJkHMFU&list=PLOocymQm7YWYpP_Qkju89vN8BykhvWO5U Playlist: Paramiko detailed explanation with Example for Network Engineers https://www.youtube.com/watch?v=A075aWJMAeM&list=PLOocymQm7YWYc73phqzbZ1S3ANrVVpUFN This is the second video on Regex Here we will see how take device configuration backup to a text file, take show command output to a text file for checking the configuration parsing logic Users paramiko and initiates SSH connection, then in python while loop we takes user inputs and executes those commands in the ssh terminal stores that file as a text file How to give sequence number for file in python,how to execute command in while loop and how to break while loop with specific user inputs ot exit python replace space in the filename with underscore python cisco save config to a text file,cisco backup python,cisco regex parsing example,save config for regex cisco,regular expression tutorial,paramiko save config,save multiple command output paramiko,python ssh config example,regex tutorial, regex python beginner,python regex intro,python while loop with ssh connection,while loop expect input from use python, cisco config terminal backup python,ssh backup filename example, Script --------- #! /usr/local/Python_envs/Python3/bin/python3 import paramiko import time host = 'csr1.test.lab' username = 'admin' password = 'admin' n = 0 while True: show_command = input("Enter Show command to execute: ") if show_command in ['','exit']: print("Exiting the Code") break SESSION = paramiko.SSHClient() SESSION.set_missing_host_key_policy(paramiko.AutoAddPolicy()) SESSION.connect(host, port=22, username=username, password=password, look_for_keys=False, allow_agent=False) DEVICE_ACCESS = SESSION.invoke_shell() DEVICE_ACCESS.send(b'term length 0\n') DEVICE_ACCESS.send(f'{show_command}\n') time.sleep(1) output = DEVICE_ACCESS.recv(65000) print (output.decode('ascii')) SESSION.close() n = n+1 with open (f"{n:02d}_{show_command.replace(' ','_')}_output.txt", 'w') as f: f.write(output.decode('ascii')) print (f"\n{'#' * 50}\nConfiguration Saved Successfully \n{'#' * 50}\n") ---------

Download

0 formats

No download links available.

Python Tutorial: Learn to Save Cisco command Output to Text file | Regex Parser Part 2 | NatokHD