ubuntu16.04下使用python3:paramiko库批量远程传文件;执行命令

#!/usr/bin/env python3

-- coding:utf-8 --

import paramiko,fileinput

def scp_ssh(ip,mypath,topath):
t = paramiko.Transport((ip,22))
t.connect(username = ‘yunnao’, password = ‘123456’)
sftp = paramiko.SFTPClient.from_transport(t)
sftp.put(mypath,topath)
t.close()
def command(ip,cm):
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(ip,22,'user,‘password’)
stdin, stdout, stderr = ssh.exec_command(cm)
# print(stdout.readlines())
ssh.close()
for x in fileinput.input(‘host.txt’):
print(x)
command(x,‘chmod -R 511 xxx.sh’)
scp_ssh(str(x), ‘/home/root/xxx.sh’, ‘/home/user_root/xxx.sh’)

你可能感兴趣的:(ubuntu16.04下使用python3:paramiko库批量远程传文件;执行命令)