【发布时间】:2023-09-18 14:40:01
【问题描述】:
我有一个 python 脚本,我正在尝试在其上安装一个 rpm 包,但是当我发送安装命令时,它不会在重新启动服务之前等待命令完成。我已经阅读了很多关于使用 recv_exit_status() 的论坛,但我认为我没有正确使用它。
这就是我所拥有的:
#!/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()
我尝试过使用 Fabric,但我似乎在某处弄乱了我的语法。
【问题讨论】: