Files
dock/实时 history 监控

80 lines
2.2 KiB
Plaintext
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 创建完整的修复脚本
cat > /tmp/fix_autostart.sh << 'EOF'
#!/bin/bash
echo "=== 修复命令监控开机自启动 ==="
# 停止现有监控
/root/monitor/cmd_monitor.sh stop >/dev/null 2>&1
# 清理旧的crontab条目
echo "1. 清理旧的crontab条目..."
(crontab -l 2>/dev/null | grep -v "cmd_monitor" | grep -v "monitor") | crontab -
# 添加新的crontab开机启动
echo "2. 设置crontab开机启动..."
(crontab -l 2>/dev/null; echo "@reboot /bin/bash /root/monitor/cmd_monitor.sh background >/dev/null 2>&1") | crontab -
# 尝试创建systemd服务
echo "3. 尝试设置systemd服务..."
if command -v systemctl >/dev/null 2>&1; then
cat > /etc/systemd/system/cmd-monitor.service << SVC_EOF
[Unit]
Description=Command Monitor Service
After=network.target
[Service]
Type=forking
User=root
ExecStart=/root/monitor/cmd_monitor.sh background
ExecStop=/root/monitor/cmd_monitor.sh stop
Restart=no
StandardOutput=null
StandardError=null
[Install]
WantedBy=multi-user.target
SVC_EOF
systemctl daemon-reload
systemctl enable cmd-monitor.service >/dev/null 2>&1
echo " ✅ systemd服务已设置"
else
echo " systemctl不可用跳过systemd设置"
fi
# 设置rc.local备用方案
echo "4. 设置rc.local备用方案..."
if [ -d /etc/rc.d ]; then
# SysV init系统
echo '/root/monitor/cmd_monitor.sh background >/dev/null 2>&1' > /etc/rc.d/rc.local
chmod +x /etc/rc.d/rc.local
elif [ -f /etc/rc.local ]; then
# systemd的rc.local兼容
grep -q "cmd_monitor" /etc/rc.local || echo '/root/monitor/cmd_monitor.sh background >/dev/null 2>&1' >> /etc/rc.local
chmod +x /etc/rc.local
else
# 创建rc.local
echo '#!/bin/bash' > /etc/rc.local
echo '/root/monitor/cmd_monitor.sh background >/dev/null 2>&1' >> /etc/rc.local
chmod +x /etc/rc.local
fi
# 立即启动监控
echo "5. 立即启动监控服务..."
/root/monitor/cmd_monitor.sh background
# 验证启动状态
echo "6. 验证启动状态..."
sleep 2
/root/monitor/cmd_monitor.sh status
echo ""
echo "=== 修复完成 ==="
echo "重启系统测试: reboot"
echo "手动检查状态: /root/monitor/cmd_monitor.sh status"
EOF
chmod +x /tmp/fix_autostart.sh
/tmp/fix_autostart.sh