Netmiko command output not captured properly on device

Job ID: 36637597

Budget: ₹600 – ₹1,500 INR

The below is the 'dm raw' output collected on device.
dm raw debugging will turn on first and then after the prompt 'ICX7550-48P Switch#' appears on switch
debugging output will be generated.

unfortunately netmiko module in python is not writing the complete output to text file.

It is only writing until below

ICX7550-48P Switch#dm raw
Raw packet debugging is on now

How to make it write whole command output to text file

I believe netmiko works based on '#' symbol and it is only taking until 'Raw packet debugging is on now' because it has '#' symbol in next line.

Reference:
=========
Below article helps you to understand the problem better
https://github.com/ktbyers/netmiko/issues/1777

Output:

ICX7550-48P Switch#dm raw
Raw packet debugging is on now <<<end writing to text file
ICX7550-48P Switch#Debug: May 22 23:32:17
RX [1173377]10.177.95.3 ->224.0.0.2 UDP S=8888 D=8888 port: mgmt1
Debug: May 22 23:32:17
RX [1173377]02e052c5d6d5 ->Broadcast ARP Req S=10.177.95.1 D=10.177.95.1 port: mgmt1
Debug: May 22 23:32:17
RX [1173378]748ef8d42380 ->778ef8d42380 Len=31 port: mgmt1
Debug: May 22 23:32:18
RX [1173378]78a6e122afa2 ->0180c2000000 Len=39 (BPDU) port: 2/1/9
Debug: May 22 23:32:18
RX [1173378]78a6e122afa3 ->0180c2000000 Len=39 (BPDU) port: 1/1/9
Debug: May 22 23:32:18
RX [117337b]748ef8d42380 ->778ef8d42380 Len=31 port: mgmt1
Debug: May 22 23:32:18
RX [117337e]748ef8d42380 ->778ef8d42380 Len=31 port: mgmt1
Debug: May 22 23:32:18
RX [1173381]10.177.95.3 ->224.0.0.2 UDP S=8888 D=8888 port: mgmt1

Script:
========
from netmiko import ConnectHandler
import time
import sys

# create a dictionary with the connection details
devices = {
"device_type": "ruckus_fastiron",
"ip": "10.176.14.169",
"username": "super",
"password": "pass",
"port" : "3004",
}



# create an SSH connection to the device
ssh_conn = ConnectHandler(**devices)


def log_into_device():





file = open('output.txt', 'a')



dm_raw_output = ssh_conn.send_command(
"dm raw",
expect_string=r"#",
read_timeout=90) #make sure logging console is enabled
time.sleep(15)

# Write outputs to file above

file.write(dm_raw_output)
time.sleep(15)


#to change file access modes
#file.close()
file = open('output.txt',"r+")

print(file.read())
print ()
file.close()


# Loop through devices and log in every 5 minutes
while True:
for device in devices:
log_into_device()
time.sleep(30) # polling interval in seconds before running again
Related categories: Python Linux Micropython