Closed kaykuok closed 4 years ago
I have changed the script with method of send_command_timing in the interactive part, it works fine with no error and all output can be written to the log file. Thanks.
with open(str(IP) + '_v' + str(Date) + '.log', 'a', newline='') as SaveOutput: cmds_output = net_connect.send_command("display diagnostic-information", "") cmds_output = net_connect.send_command_timing('n\n') Date = time.strftime('%Y%m%d%H%M%S', time.localtime()) SaveOutput.writelines(f'#{cmd}\n{cmds_output}\n')
Hi everyone, i am new to python and i am writing a script for obtaining the output of "display diagnostic-information" of H3c switches.
The code is listed as below, `import openpyxl import time import netmiko from netmiko import ConnectHandler from netmiko.ssh_exception import NetMikoTimeoutException, NetMikoAuthenticationException import getpass import logging from netmiko.base_connection import BaseConnection
my_wb = openpyxl.Workbook() my_sheet = my_wb.active localtime = time.localtime(time.time())
UName = input("Username:") PW = getpass.getpass("Login Password: ") EN = getpass.getpass("Enable Password: ")
for IP in iplist: Port = 23 Date = time.strftime('%Y%m%d%H%M%S', time.localtime())
*** The following line is to "display diagnostic-information" and write to the file *
* End *****
`
But i am getting the error as below,
File "d:\ShareCache\user\Python\H3C_Telnet\TelnettoH3CSwitch.py", line 115, in <module> cmds_output = net_connect.send_command('n\n',cmd_verify=False) File "C:\Users\user\AppData\Local\Programs\Python\Python38-32\lib\site-packages\netmiko\utilities.py", line 347, in wrapper_decorator return func(self, *args, **kwargs) File "C:\Users\user\AppData\Local\Programs\Python\Python38-32\lib\site-packages\netmiko\base_connection.py", line 1429, in send_command raise IOError( OSError: Search pattern never detected in send_command_expect: Before\ pressing\ ENTER\ you\ must\ choose\ 'YES'\ or\ 'NO'\[Y/N\]:
And the command output is not able to write to the .log file, but it existi in the netmiko debug logger file like below,
`
DEBUG:netmiko:Exiting disable_paging
DEBUG:netmiko:read_channel:
DEBUG:netmiko:write_channel: b'super\r\n'
DEBUG:netmiko:Pattern is: (sw-itch|ssword)
DEBUG:netmiko:read_channel:
DEBUG:netmiko:read_channel: super
Please input the password to change the privilege level, press CTRL_C to abort.
Password: DEBUG:netmiko:Pattern found: (sw-itch|ssword) super
Please input the password to change the privilege level, press CTRL_C to abort.
Password: DEBUG:netmiko:write_channel: password!\r\n' DEBUG:netmiko:Pattern is: sw-itch DEBUG:netmiko:read_channel: DEBUG:netmiko:read_channel:
User privilege level is 3, and only those commands can be used
whose level is equal or less than this.
Privilege note: 0-VISIT, 1-MONITOR, 2-SYSTEM, 3-MANAGE