Files
tools/scripts/simple_monitor.sh
hubian 7972b06528 feat: 添加极简版进程监控脚本 simple_monitor.sh
- 只需修改3处配置:检测间隔、检查命令、执行命令
- 代码简洁,易于理解和修改
- 适合快速部署使用
2026-03-26 17:17:01 +08:00

19 lines
662 B
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
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.
#!/bin/bash
# 简单进程监控脚本
# 每隔几秒检查一次进程,进程消失则执行命令
# ==================== 配置区域(只需改这里) ====================
CHECK_INTERVAL=10 # 每隔多少秒检查一次
CHECK_CMD="pgrep myapp" # 检查命令进程存在应返回0
EXEC_CMD="echo 'Process died'" # 进程消失后执行的命令
# ===============================================================
while true; do
if ! eval "$CHECK_CMD" >/dev/null 2>&1; then
echo "[$(date '+%H:%M:%S')] Process not found, executing: $EXEC_CMD"
eval "$EXEC_CMD"
break
fi
sleep "$CHECK_INTERVAL"
done