#!/usr/bin/python
import paramiko, os
from getpass import getpass
# Setting Variables
Hosts = [ '192.168.1.1', '192.168.1.2'] #IPs changed for posting
username = 'root'
print 'Enter root password on remote computer:'
password = getpass()
port = 22
File = 'Nessus-6.11.2-es7.x86_64.rpm'
for host in Hosts:
print 'Finished copying files. Now executing on remote computer'
#Setting up SSH session to run commands
remote_client = paramiko.SSHClient()
remote_client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
remote_client.connect(host, username=username, password=password)
InstallNessus = 'rpm -U --percent %s'%File
stdin, stdout, stderr = remote_client.exec_command(InstallNessus)
stdout.channel.recv_exit_status()
lines = stdout.readlines()
for line in lines:
print line
stdin, stdout, stderr = remote_client.exec_command('systemctl restart nessusd.service')
remote_client.close()
我尝试使用织物,但我似乎在某处弄乱了我的语法。
add
get_pty=True
这将等到命令执行完成。
stdin,stdout,stderr = self.ssh.exec_command(command,get_pty=True)
,而不是
channel.recv_exit_status()
。 ,既然您正在尝试通过许多服务器运行相同的命令,那么类似于paralallel-ssh
的拟合度比paramiko更快,依次更快。