tftp太繁琐,所以我直接把配置文件读取出来进行备份。
前置需要准备一台可以连接交换机的linux系统。
1、python部分
首先安装python的paramiko
我用的python2.7.5
pip install paramiko
代码如下:
# encoding=utf-8
import paramiko
import time
client = paramiko.SSHClient()
client.load_system_host_keys()
# connect to client
client.connect('192.168.1.254',22,'user','password',allow_agent=False,look_for_keys=False)
# get shell
ssh_shell = client.invoke_shell()
# ready when line endswith '>' or other character
while True:
line = ssh_shell.recv(1024)
#print line
if line and line.endswith('>'):
break;
# send command
ssh_shell.sendall( 'dis cu' + '\n')
# get result lines
lines = []
while True:
line = ssh_shell.recv(1024)
if line and line.endswith('>'):
break;