Answer the question
In order to leave comments, you need to log in
How to send acknowledgment commands to cisco hardware via python script?
Hello, the task is to write a script to automate backups of cisco equipment. The problem is, I don't know how to send confirmation commands.
Here is what the script looks like at the moment:
#Подключенные библиотеки
import getpass
import sys
from netmiko import ConnectHandler
#Адрес оборудование
devices = ['192.168.125.88']
#словарь, в котором указываются параметры устройства
for ip in device:
print('connetion to device {}'.format(ip))
device = {
'device_type': 'cisco_ios',
'ip': '192.168.125.88',
'username': 'cisco',
'password': 'passwd',
'secret': 'enpasswd'
'port' : 22,
}
with ConnectHandler(**device) as ssh: #подключение по ssh
ssh.enable() #вход в привилегированный режим
result = ssh.send_command('show ip int br')
print(result)
ssh.send_command('copy running-config ftp')
Answer the question
In order to leave comments, you need to log in
maybe if you have grown to a python, then fuck already all sorts of old-fashioned ftp?
result = ssh.send_command('show run')
with open(f"{device_name}.cfg") as f:
f.write(result)
man expect
man cbackup
man rancid
I wonder why people write their bikes if there is a lot of software that does it?
Thanks to everyone who looked, I added a couple of conditions to my script:
net_connect = ConnectHandler(**device)
command = "copy startup-config ftp:"
print()
print(net_connect.find_prompt())
output = net_connect.send_command_timing(command)
if "Address or name of remote host []?" in output:
output += net_connect.send_command_timing(
"address of the server where the backup will be sent", strip_prompt=False, strip_command=False
)
if "Destination filename [zhgn-sw-confg]?" in output:
output += net_connect.send_command_timing(
"file name can be entered the same as hostname", strip_prompt=False, strip_command=False
)
Yes, I understand it is possible for experts and "CSV Experts" My output will seem wild, but I have just started learning python. Perhaps in the future I will make or find a simplified version of this task. ASAP, I'll post it here, but for now, this option may be suitable as a temporary solution
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question