#!/bin/bash
# 文件路径
CONFIG_FILE="/opt/nezha/agent/config.yml"
# 检查文件是否存在
if [[ ! -f $CONFIG_FILE ]]; then
echo "文件不存在: $CONFIG_FILE"
exit 1
fi
# 使用 sed 修改配置文件
sed -i 's/disable_command_execute: false/disable_command_execute: true/' "$CONFIG_FILE"
# 检查是否修改成功
if grep -q "disable_command_execute: true" "$CONFIG_FILE"; then
echo "修改成功: disable_command_execute 已设置为 true"
else
echo "修改失败"
exit 1
fi
# 重启 nezha-agent 服务
echo "正在重启 nezha-agent 服务..."
sudo systemctl restart nezha-agent.service
# 检查服务状态
if systemctl is-active --quiet nezha-agent.service; then
echo "nezha-agent 服务已成功重启"
else
echo "nezha-agent 服务重启失败,请检查日志"
exit 1
fi
感谢分享,可以添加关闭自动更新(disable_auto_update)和内网穿透(disable_nat),作为可选项,默认注释掉。
@栀子花开 #2 手动设置的话,请参考wiki
https://nezha.wiki/guide/q7.html
@trouble9263
在哪里设置
#1
@trouble9263 感谢#3