Unable to collect 'sh tech-support' from Cisco

Hi guys,
I can’t get command output from comamand show tech-support from cisco devices. The below code works while collecting logs for small outputs like ‘show version’ etc. But the script hangs when trying to run tech-support. I understand it is related to read_time, but I can’t find solution(i’m python beginner :confused: ).

import getpass
import re
import datetime
from pathlib import Path
from scrapli import Scrapli

username = 'cisco'
password = getpass.getpass("Enter password: ")
enable_password = getpass.getpass("Enter enable password: ")

with open('device_ip.txt') as routers:
    for IP in routers:
        IP = IP.strip()
        Router = {
            "host": IP,
            "auth_username": username,
            "auth_password": password,
            "auth_secondary": enable_password,
            "auth_strict_key": False,
            "transport": "paramiko",
            "platform": "cisco_iosxe",
            "transport_options": {
                "paramiko": {
                    "kex_algorithms": [
        connection = Scrapli(**Router)
        print ('Connecting to ' + IP)
        output = connection.send_commands_from_file("command_list.txt")
        #output = connection.send_configs_from_file("config_changes.txt")

# Extract the hostname from the tech configuration
        hostname = re.search(r"hostname (.+)", output.result)
        if hostname:
            hostname = hostname.group(1)
            hostname = "unknown_hostname"

# Create the backup directory if it doesn't exist
        backup_dir = Path(".") 
        backup_dir.mkdir(parents=True, exist_ok=True)

# Save the output to a file with the date and hostname
# Save the output to a file with the date and hostname
        current_date = datetime.datetime.now().strftime("%Y-%m-%d")
        file_name = f"{current_date}_{hostname}.txt"
        file_path = backup_dir / file_name

        with file_path.open("w") as f:

        print(f"Saved config to: {file_path}")

Enter password:
Enter enable password:
Connecting to

Traceback (most recent call last):
File “/home/user/Python-Net-Eng/.venv/lib/python3.11/site-packages/scrapli/transport/plugins/paramiko/transport.py”, line 275, in read
buf: bytes = self.session_channel.recv(65535)
File “/home/user/Python-Net-Eng/.venv/lib/python3.11/site-packages/paramiko/channel.py”, line 697, in recv
out = self.in_buffer.read(nbytes, self.timeout)
File “/home/user/Python-Net-Eng/.venv/lib/python3.11/site-packages/paramiko/buffered_pipe.py”, line 150, in read
File “/usr/lib/python3.11/threading.py”, line 324, in wait
gotit = waiter.acquire(True, timeout)
File “/home/user/Python-Net-Eng/.venv/lib/python3.11/site-packages/scrapli/decorators.py”, line 76, in _signal_raise_exception
return _handle_timeout(transport=transport, logger=logger, message=message)
File “/home/user/Python-Net-Eng/.venv/lib/python3.11/site-packages/scrapli/decorators.py”, line 141, in _handle_timeout
raise ScrapliTimeout(message)
scrapli.exceptions.ScrapliTimeout: timed out sending input to device

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File “/home/user/Python-Net-Eng/test.py”, line 39, in
output = connection.send_commands_from_file(“command_list.txt”)
File “/home/user/Python-Net-Eng/.venv/lib/python3.11/site-packages/scrapli/driver/network/sync_driver.py”, line 353, in send_commands_from_file
return super().send_commands_from_file(
File “/home/user/Python-Net-Eng/.venv/lib/python3.11/site-packages/scrapli/driver/generic/sync_driver.py”, line 283, in send_commands_from_file
return self.send_commands(
File “/home/user/Python-Net-Eng/.venv/lib/python3.11/site-packages/scrapli/driver/network/sync_driver.py”, line 300, in send_commands
responses = super().send_commands(
File “/home/user/Python-Net-Eng/.venv/lib/python3.11/site-packages/scrapli/driver/generic/sync_driver.py”, line 236, in send_commands
response = self._send_command(
File “/home/user/Python-Net-Eng/.venv/lib/python3.11/site-packages/scrapli/decorators.py”, line 306, in decorate
result = wrapped_func(*args, **kwargs)
File “/home/user/Python-Net-Eng/.venv/lib/python3.11/site-packages/scrapli/driver/generic/sync_driver.py”, line 144, in _send_command
raw_response, processed_response = self.channel.send_input(
File “/home/user/Python-Net-Eng/.venv/lib/python3.11/site-packages/scrapli/decorators.py”, line 242, in decorate
return wrapped_func(*args, **kwargs)
File “/home/user/Python-Net-Eng/.venv/lib/python3.11/site-packages/scrapli/channel/sync_channel.py”, line 492, in send_input
buf += self._read_until_prompt()
File “/home/user/Python-Net-Eng/.venv/lib/python3.11/site-packages/scrapli/channel/sync_channel.py”, line 137, in _read_until_prompt
File “/home/user/Python-Net-Eng/.venv/lib/python3.11/site-packages/scrapli/channel/sync_channel.py”, line 69, in read
buf = self.transport.read()
File “/home/user/Python-Net-Eng/.venv/lib/python3.11/site-packages/scrapli/transport/plugins/paramiko/transport.py”, line 282, in read
raise ScrapliConnectionError(msg) from exc
scrapli.exceptions.ScrapliConnectionError: encountered EOF reading from transport; typically means the device closed the connection
(.venv) user@python3lab:~/Python-Net-Eng$

Could you try entering an actual path as opposed to just a period and test it?

The following line you have outside of the with as body


but its counterpart (connection.open()), is within the with as body. Does it belong inside the body?

I think it belongs to inside the body :slight_smile: I tryed to change how you said, but then does’t work at all. I attached errors, maybe now it will be more clear. Like I said script works fine, but problem is with only one cisco command(show tech-support). To get answer from this command script need to wait, but he doesn’t want to do it. :slight_smile:

You forgot to attach errors … did you try including an actual path instead of the " . "?

I attached errors to the description of the problem and I added a extra description. I did not try to include an actual path instead of the “.” I think it is not related with my problem, when trying to get a large amount of output from command show tech-support.

I am pretty sure that the show tech takes to long to print. Maybe set the timeout to a bigger value. Depending on your device show tech takes really long 5 to 10 minutes… it depends. I always save the show tech to the flash of the network device , wait wait wait and than collect the file from the flash. This is good because it does not take longer on connections with high round trip times.

1 Like

and how to do this in my script?

On Cisco iOS XE you have to do show tech | redirect flash:show-tech.txt

Just send the command the device and last step would be use scp to copy the file to your box or use the file transfer function of your network device.

mmm, it is not so simple :slight_smile: we have about 100 devices and we need that all .txt with show tech output file have uniqea name, by device hostname, because of that we need to solve this problem. For example if I do show tech on simple cisco switch it works fine, but if I do on router, where is big ammount of data and needs more time to get that information, then the script not working.

after some time in google.com I found solution, it was enough “timeout_ops”: 120,

1 Like