0

Cisco ios-xr router using CLI:

RP/0/RP0#show version

Thu Nov 25 07:53:59.103 UTC

Cisco IOS XR Software, Version 6.5.32.11I

Copyright (c) 2013-2020 by Cisco Systems, Inc.

RP/0/RP0#run

Thu Nov 25 07:54:05.231 UTC

[xr-vm_node0_RP0_CPU0:~]$df

Filesystem 1K-blocks Used Available Use% Mounted on

rootfs 3966080 1332040 2412860 36% /

76892 11848320 43% /mnt/ecu/vdd

[xr-vm_node0_RP0_CPU0:~]$

Using python: I am able to run show commands using Connecthandler .send.command:

from netmiko import ConnectHandler
import subprocess
Network_Device = {"host": "10.111.22.333", "username": "USER123", "password": "Pass123",     "device_type": "cisco_xr",}

Connect = ConnectHandler(**Network_Device)
Connect.enable()
version1 = "show version"
print(Connect.send_command(version1))

But not able to run 'df' or 'ls' commands, as not able to reach bash prompt i reach by running 'run' command on router.

I tried:

disk1files = subprocess.run("df", stdout=subprocess.PIPE)
print(disk1files.stdout.decode())

But seems its wrong. Please suggest the right library or code I can use here.

This is my first question here, so bear some silly questions or mistakes done in code

Paulw11
  • 108,386
  • 14
  • 159
  • 186

1 Answers1

1

if on DF you are referring to "Don't fragment" then it is posible to send it like

Connect.send_command("ping 192.168.10.10 df-bit size 1600")

where 1600 represents MTU, and for ls commands is link command,

Connect.send_command("ls-active") 
Connect.send_command("ls-active-enabled") 

but if you are referring to df and ls in linux (disk free and list files..) then you can use os module for sending commands:

import os
os.system("ls -l")

or use call from subprocess module:

from subprocess import call
call(["ls", "-l"])

If you need to acccess cisco bash:

switch# configure terminal
switch(config)# feature bash-shell
switch# run?
  run         Execute/run program
  run-script  Run shell scripts

switch# run bash?
  bash  Linux-bash

switch# run bash 
bash-4.2$ whoami
admin
bash-4.2$ pwd
/bootflash/home/admin
bash-4.2$
Thyrus
  • 458
  • 2
  • 13