def loginandrun(hostname,uname,pwd,command):
try:
log.info("Establishing ssh connection")
client = getsshClient()
client.load_system_host_keys()
client.connect(hostname)#,username=uname)#,password=pwd)
except paramiko.AuthenticationException:
print("Authentication failed, please verify your credentials: %s")
except paramiko.SSHException as sshException:
print("Unable to establish SSH connection: %s" % sshException)
except paramiko.BadHostKeyException as badHostKeyException:
print("Unable to verify server's host key: %s" % badHostKeyException)
try:
stdin, stdout, stderr = client.exec_command(command)
result = stderr.read()
if len(result) > 0:
print("hit error" + result)
except Exception as e:
print("Operation error: %s", e)
# Any new implementation to use this method
paramiko_helper.py 文件源码
python
阅读 20
收藏 0
点赞 0
评论 0
评论列表
文章目录