詳解python通過paramiko模塊批量執(zhí)行ssh命令
來源:懂視網(wǎng)
責(zé)編:小采
時(shí)間:2020-11-27 14:24:54
詳解python通過paramiko模塊批量執(zhí)行ssh命令
詳解python通過paramiko模塊批量執(zhí)行ssh命令:多臺(tái)設(shè)備批量執(zhí)行ssh命令,目前是串行,后期會(huì)加入多線程實(shí)現(xiàn)并行,直接上源碼注意不能執(zhí)行top等動(dòng)態(tài)命令#!/usr/bin/env python # -*- coding:utf-8 -*- __author__ = 'babyshen' __version__ = '1.0.0'
導(dǎo)讀詳解python通過paramiko模塊批量執(zhí)行ssh命令:多臺(tái)設(shè)備批量執(zhí)行ssh命令,目前是串行,后期會(huì)加入多線程實(shí)現(xiàn)并行,直接上源碼注意不能執(zhí)行top等動(dòng)態(tài)命令#!/usr/bin/env python # -*- coding:utf-8 -*- __author__ = 'babyshen' __version__ = '1.0.0'
多臺(tái)設(shè)備批量執(zhí)行ssh命令,目前是串行,后期會(huì)加入多線程實(shí)現(xiàn)并行,直接上源碼
注意不能執(zhí)行top等動(dòng)態(tài)命令
#!/usr/bin/env python
# -*- coding:utf-8 -*-
__author__ = 'babyshen'
__version__ = '1.0.0'
import paramiko
class SSh(object):
def __init__(self,port,username,password):
self.port = port
self.username = username
self.password = password
def ssh_con(self,host,ip,cmd):
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(ip,self.port,self.username,self.password)
stdin, stdout, stderr = ssh.exec_command(cmd)
res,err = stdout.read(),stderr.read()
result = res if res else err
print('