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

Published: 14 March 2021
on channel: NetworkEvolution
4,489
42

#CiscoBackupPython #ParamikoSShbackup #ConfigBackupPython

Playlist: Learn to Parse Cisco Configuration using Python RegEx:re Tutorial
   • Learn to Parse Cisco Configuration us...  

Playlist: Python Learning for Network Engineers
   • Python learning for Network Engineers...  

Playlist: Learn to Read Data From CSV Using Python
   • Learn to Read Data from CSV (IP/Confi...  

Playlist: Paramiko detailed explanation with Example for Network Engineers
   • Paramiko Tutorial :Part1  How SSH Hos...  

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")
---------


Watch video Python Tutorial: Learn to Save Cisco command Output to Text file | Regex Parser Part 2 online without registration, duration hours minute second in high quality. This video was added by user NetworkEvolution 14 March 2021, don't forget to share it with your friends and acquaintances, it has been viewed on our site 4,489 once and liked it 42 people.