Friday, August 14, 2020

Netmiko TFTP Issue when using scraped variables

Hello all,

I am attempting to write a python script that will upload the running config of the device to a TFTP server - altering the txt file name to represent the device's hostname and also the days date.

I have grabbed the hostname from a show run command.

When attempting this script it hangs for a while, then returns this error:

OSError: Search pattern never detected in send_command_expect: GBA\-00\-SWA\-Build\-01\#

Which I understand to be Netmiko complaining that I am not confirming the filename on the device.

I have tried using the expect_script method but that doesnt seem to work either.

Here is my code if anyone would like to have a look at it.

from netmiko import ConnectHandler
from datetime import date

TFTP_SERVER = "10.137.79.40"
date = date.today()
filedate = date.strftime("%d/%m/%Y")

device1 = {
'device_type': 'cisco_ios',
'host': '10.200.252.29',
'username': '*******',
'password': '*******',
}
my_devices = [device1]
i = 0
for device in my_devices:
    i += 1
    name = f"device{str(i)}"
    net_connect = ConnectHandler(**device)
    net_connect.enable()
    result = net_connect.send_command("show run | in hostname")
    result = result.split()
    hostname = result[1]

print(hostname)
print(filedate)
    copy_command = "copy running-config tftp://"+TFTP_SERVER+"/"+hostname+"_"+filedate
    output = net_connect.send_command(copy_command)
if 'Address or name of remote host' in output:
        output += net_connect.send_command_timing('\n')
if 'Destination filename' in result:
        output += net_connect.send_command('\n')
    net_connect.disconnect
print(output)

And here is the output

Traceback (most recent call last):

File "//****/python/NCM2.py", line 33, in <module>

output = net_connect.send_command(copy_command)

File "C:\Users\geeo\AppData\Local\Programs\Python\Python38-32\lib\site-packages\netmiko\base_connection.py", line 1405, in send_command

raise IOError(

OSError: Search pattern never detected in send_command_expect: GBA\-00\-SWA\-Build\-01\#



No comments:

Post a Comment