Tuesday, April 28, 2020

Netmiko save config on Cisco question

start_time = datetime.now() net_connect = ConnectHandler(**device) cmd = 'copy flash:/c880data-universalk9-mz.154-2.T1.bin flash:/test1.bin' output = net_connect.send_command( cmd, expect_string=r'Destination filename' ) output += net_connect.send_command( '\n', expect_string=r'#', delay_factor=2 ) end_time = datetime.now() 

Hi, so i've just started getting into Python and Netmiko and i'm wondering what exactly this part of a script does? I think i have a fairly good idea but a few things are confusing me.The.....

output += net_connect.send_command( '\n', expect_string=r'#', 

.....part. This script is to get around a prompt from a router when asking for another answer to the save config on the Cisco CLI. It looks like its using the expect_string Destination filename to look for that in the output from the command, okay fair enough i get that, but it looks like the output variable is being combied with another send.command() command as well looking for a new line and then expect_string=r'#' which i've no clue what it is doing...I know the delay factor is used for timeout, it's mainly the other things i've mentioned which i'm at a bit of a loss about...

Thanks again everyone for the help

Update after more thinking.....

Is the "expect_string" argument just looking for that identifier, so a "#" and "Destination filename" and once it finds it, it moves onto the next piece of code?



No comments:

Post a Comment