python实现ssh登录后卡死捕获回显_python,paramiko,ssh异常ssh会话未激活

I'm working on a python script that goes to each switch in our network, and issues a copy running-config TFTP command, that backs up the running configuration of the switch. I'm on windows and utilizing the paramiko library in Python 2.7.

The script itself is pretty simple, all it does is create a directory called "Backups" if one doesn't exist already, and another directory named today's date, and then uses that directory for the TFTP. And it starts up the TFTP Server. Then it simply issues the copy command via ssh.

This issue I am trying to overcome is during connectSwitch(). Specifically on the second ssh.exec_command('x.x.x.x'). If you don't know switches, the copy running-config tftp, is the first command sent, the switch asks for a host, and the second command is sent, that contains the host IP. And the third command is the directory where you want the file to be located.

import paramiko

import getpass

import os

import time

from datetime import date

paramiko.util.log_to_file("filename.log")

d = date.today()

filename = d.strftime("%Y.%m.%d")

UUser = "first.last"

print UUser

UPass = getpass.getpass('Enter your Password: ')

def writeFile(text, Host):#Writes to the Switches backup File

fl = open(Host+".txt", 'w')

fl.wri

你可能感兴趣的:(python实现ssh登录后卡死捕获回显_python,paramiko,ssh异常ssh会话未激活)