Disable CLI paging

socraticmethod
Member
 
Posts: 10
Joined: Tue Jan 10, 2017 12:05 am
Has thanked: 1 time
Been thanked: 1 time

Disable CLI paging

Mon Jul 27, 2020 5:52 pm

Hey all, anyone know if there's a convenient way to disable paging when SSHed into the CLI? I'm working on some custom Nornir/Netmiko config backup automation and having to press Space or Enter to get the full config is causing a bit of a headache. It's not impossible to get around this, just figured I would ask first over here before rewriting the Python scripting.

Thanks!

socraticmethod
Member
 
Posts: 10
Joined: Tue Jan 10, 2017 12:05 am
Has thanked: 1 time
Been thanked: 1 time

Re: Disable CLI paging

Thu Jul 30, 2020 10:32 am

Rather than paging through the show config output I found it easier to enter the cmdline context and simply copy the config.json file.
For anyone else using Nornir/Netmiko for config backups, copied below is the Python script to get it done.



Code: Select all
from nornir import InitNornir
from nornir.plugins.tasks.files import write_file
from nornir.plugins.tasks.networking import netmiko_send_command
from nornir.plugins.functions.text import print_result
import pathlib

#
# Initialize Nornir with config file
#
nr = InitNornir(config_file="config.yaml")

#
# Get list of devices by OS / Platform
#
devices = nr.filter(platform="netonix")

#
# Configure device connection settings
#
def backup_netonix_config(task):
 task.host.open_connection(
 "netmiko",
 configuration=task.nornir.config,
 platform="linux",
 port="22",
 username="yourusername",
 password="yourpassword",
 )
#
# Create backup directory and enter cmdline context on Netonix
#
backup_dir = "config-backups/"
 pathlib.Path(backup_dir).mkdir(exist_ok=True)
 task.run(
 task=netmiko_send_command,
 use_timing="True",
 command_string="cmdline",
 delay_factor=2,
 )
#
# Concatonate config.json file
#
output = task.run(
 task=netmiko_send_command,
 use_timing="True",
 command_string="cat config.json",
 delay_factor=2,
 )
#
# Write hostname with config output to config-backups folder
#
task.run(
 task=write_file,
 content=output.result,
 filename=str(backup_dir) + task.host.name,
 )
#
# Launch script and make it all happen
#
def main():
 result = devices.run(task=backup_netonix_config, num_workers=100)
 print_result(result, vars=["stdout"])

main()

Return to General Discussion

Who is online

Users browsing this forum: No registered users and 23 guests