python paramiko ssh远程连接

来源:互联网 发布:手机数学公式编辑软件 编辑:程序博客网 时间:2024/04/30 09:30

使用paramiko进行手术远程连接,执行系统命令~

#!/usr/bin/env python# -*-coding:UTF-8-*-import paramiko,sysssh = paramiko.SSHClient()ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())ssh.connect(host='*.*.*.*',22,username='wang',password='wang',timeout=4)icmd = '''sudo su - root -c 'rabbitmqctl list_vhosts | grep "/" ; "pwd" ' '''stdin,stdout,stderr = ssh.exec_command(icmd)for std in stdout.readlines():    print stdfor std in stderr.readlines():    print stdssh.close()


 

原创粉丝点击