python - FileNotFoundError : [Errno2]: No Such file or directory:

标签 python scripting centos wazuh hardening

我正在尝试为我的工作制作服务器强化脚本,其中一部分是在将连接到 SIEM 管理器的服务器上安装 wazuh-agent。
该脚本有 2 个部分,其中一个添加了 repo 条目 - 工作正常。
第二部分安装 wazuh 代理(代码如下)。当我在 shell 上运行命令时,它们工作正常,但是使用脚本它给了我以下错误。

import os 
import subprocess

wazuhrepofile = "/etc/yum.repos.d/wazuh.repo"
wazuh = "wazuh-agent"
wazuhmanager = 'WAZUHMANAGER="10.0.0.2"'

def install_wazuh(wazuh, wazuhmanager, wazuhrepofile):
    subprocess.run([wazuhmgr ,'yum', 'install', '-y', wazuh], check=True)
    print("Wazuh Agent Installed")
    subprocess.run(['systemctl', 'daemon-reload'], check=True)
    print("Daemon Reloaded")
    subprocess.run(['systemctl', 'enable', wazuh])
    print("Wazuh Agent Enabled")
    subprocess.run(['systemctl', 'start', wazuh], check=True)
    print("Wazuh-Agent Service Started!")
    subprocess.run(['sed', '-i', '"s/^enabled=1/enabled=0/"', wazuhrepofile])


install_wazuh(wazuh, wazuhmgr, wazuhrepofile)
以下是错误
[运行错误]
1

最佳答案

hj。
感谢您选择华祖。
如前所述,子进程运行 接受一系列参数,但似乎第一个需要是实际命令而不是变量赋值。
您正在做的是传递管理器 IP 以使代理自动注册到管理器。另一种可能的方法是安装代理,然后使用 代理身份验证 位于/var/ossec/bin/文件夹中。此命令还允许代理将代理名称传递给管理器,因此它将显示在警报和 UI 上,以便于识别。
命令是:/var/ossec/bin/agent-auth -m MANAGER-IP -A AGENT-NAME
有关代理注册的更多信息,请访问 here有关代理身份验证工具的信息,here
如果您还有其他问题,请随时提问。
干杯

关于python - FileNotFoundError : [Errno2]: No Such file or directory:,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70550712/

相关文章:

python - 在numpy中绘制随机元素

python - 如何以编程方式使用 Microsoft Word 的拼写/语法检查器?

Web 服务器上的 Python 脚本

python - 正则表达式查找搜索词并将结果放入另一个数据文件中?

python - Apache 上的 Django 网站,wsgi 失败

Python赋值索引错误

c# - 用 C# 编写脚本?

arrays - 如何在 Bash 中按降序对字符串数组进行排序?

centos - 加载共享库时出错

linux - 如何在centos中设置通配符ssl