def create_paramiko_obj(host,command):

    ssh = paramiko.SSHClient()
    ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    ssh.connect(hostname=host, port=22, username="root", password="admin123.")
    try:
        stdin, stdout, stderr = ssh.exec_command(command)
    except Exception as e:
        print("在主机{host}执行命令{command}失败,原因{error},脚本停止!".format(host=host,command=command,error=e))
        return e
    else:
        res = stdout.read()
    finally:
        ssh.close()
    return str(res,encoding="utf-8")

 

相关文章:

  • 2022-01-02
  • 2021-11-22
  • 2021-11-22
  • 2021-10-19
  • 2022-12-23
猜你喜欢
  • 2021-10-19
  • 2021-10-19
  • 2021-11-12
  • 2022-01-02
  • 2021-12-23
  • 2021-12-15
相关资源
相似解决方案