Reboot Checker
Detect unexpected reboots and track boot history. Useful for security monitoring — flags when a system restarts unexpectedly.
Quick Start
CODEBLOCK0
How It Works
- 1. On first run, records current boot time to state file
- On subsequent runs, compares current boot time with last known
- If boot time changed unexpectedly → alerts
- State file:
~/.reboot-check-state (customizable with --state)
Output
CODEBLOCK1
Integration
Use with cron or heartbeat systems:
CODEBLOCK2
Options
- -
--state FILE — State file path (default: ~/.reboot-check-state) - INLINECODE4 — Show recorded boot history
- INLINECODE5 — Reset state to current boot
- INLINECODE6 — Output as JSON
技能名称: reboot-checker
详细描述:
重启检测器
检测意外重启并追踪启动历史。适用于安全监控——当系统意外重启时发出警报。
快速开始
bash
检测意外重启(在启动时或首次心跳时运行)
bash {baseDir}/scripts/check-reboot.sh
查看启动历史
bash {baseDir}/scripts/check-reboot.sh --history
重置状态(将当前启动标记为已知)
bash {baseDir}/scripts/check-reboot.sh --reset
工作原理
- 1. 首次运行时,将当前启动时间记录到状态文件
- 后续运行时,将当前启动时间与上次已知时间进行比较
- 如果启动时间意外变化 → 发出警报
- 状态文件:~/.reboot-check-state(可通过 --state 自定义)
输出
STATUS: CLEAN — 自上次检查以来未重启
STATUS: REBOOTED — 自上次检查以来系统已重启
STATUS: FIRST_RUN — 首次运行,正在记录启动时间
集成
与 cron 或心跳系统配合使用:
bash
Cron:每小时检查一次
0
/path/to/check-reboot.sh >> /var/log/reboot-check.log
或在心跳脚本中使用
RESULT=$(bash check-reboot.sh)
[[ $RESULT ==
REBOOTED ]] && echo 警报:检测到意外重启!
选项
- - --state FILE — 状态文件路径(默认:~/.reboot-check-state)
- --history — 显示记录的启动历史
- --reset — 将状态重置为当前启动
- --json — 以 JSON 格式输出