Skill: hostilespider/reboot-checker (version 1.0.0)

--- name: reboot-checker description: Detect unexpected system reboots and alert when the system comes back online. Tracks boot history and flags suspicious restarts. metadata: {"openclaw":{"emoji":"🔄","requires":{"bins":["bash"]}}} --- # Reboot Checker Detect unexpected reboots and track boot history. Useful for security monitoring — flags when a system restarts unexpectedly. ## Quick Start ```bash # Check for unexpected reboot (run at startup or on first heartbeat) bash {baseDir}/scripts/check-reboot.sh # View boot history bash {baseDir}/scripts/check-reboot.sh --history # Reset state (mark current boot as known) bash {baseDir}/scripts/check-reboot.sh --reset ``` ## How It Works 1. On first run, records current boot time to state file 2. On subsequent runs, compares current boot time with last known 3. If boot time changed unexpectedly → alerts 4. State file: `~/.reboot-check-state` (customizable with `--state`) ## Output ``` STATUS: CLEAN — No reboot since last check STATUS: REBOOTED — System rebooted since last check STATUS: FIRST_RUN — First time running, recording boot time ``` ## Integration Use with cron or heartbeat systems: ```bash # Cron: check every hour 0 * * * * /path/to/check-reboot.sh >> /var/log/reboot-check.log # Or in a heartbeat script RESULT=$(bash check-reboot.sh) [[ "$RESULT" == *"REBOOTED"* ]] && echo "ALERT: Unexpected reboot!" ``` ## Options - `--state FILE` — State file path (default: `~/.reboot-check-state`) - `--history` — Show recorded boot history - `--reset` — Reset state to current boot - `--json` — Output as JSON

path: scripts/check-reboot.sh
content: #!/bin/bash
# Reboot Checker — Detect unexpected system reboots
# Generic version — no hardcoded paths or personal data

STATE_FILE="${STATE_FILE:-$HOME/.reboot-check-state}"
HISTORY_FILE="${HISTORY_FILE:-$HOME/.reboot-check-history}"

# Parse args
while [[ $# -gt 0 ]]; do
    case $1 in
        --state) STATE_FILE="$2"; shift 2 ;;
        --history) 
            if [ -f "$HISTORY_FILE" ]; then
                cat "$HISTORY_FILE"
            else
                echo "No history recorded yet."
            fi
            exit 0 ;;
        --reset) rm -f "$STATE_FILE"; echo "State reset."; exit 0 ;;
        --json) JSON_OUT=1; shift ;;
        *) shift ;;
    esac
done

# Get current boot time
CURRENT_BOOT=$(who -b 2>/dev/null | awk '{print $3, $4}')
if [ -z "$CURRENT_BOOT" ]; then
    CURRENT_BOOT=$(uptime -s 2>/dev/null || stat -c %y /proc/1 2>/dev/null | cut -d. -f1)
fi
CURRENT_BOOT_TS=$(date -d "$CURRENT_BOOT" +%s 2>/dev/null || echo 0)

# First run
if [ ! -f "$STATE_FILE" ]; then
    echo "$CURRENT_BOOT_TS" > "$STATE_FILE"
    echo "$CURRENT_BOOT | first_recorded" >> "$HISTORY_FILE"
    if [ "$JSON_OUT" = "1" ]; then
        echo '{"status":"FIRST_RUN","boot_time":"'"$CURRENT_BOOT"'"}'
    else
        echo "STATUS: FIRST_RUN — Recording boot time: $CURRENT_BOOT"
    fi
    exit 0
fi

# Compare
LAST_KNOWN=$(cat "$STATE_FILE" 2>/dev/null || echo 0)

if [ "$CURRENT_BOOT_TS" -gt "$LAST_KNOWN" ]; then
    echo "$CURRENT_BOOT_TS" > "$STATE_FILE"
    echo "$CURRENT_BOOT | reboot_detected" >> "$HISTORY_FILE"
    if [ "$JSON_OUT" = "1" ]; then
        echo '{"status":"REBOOTED","boot_time":"'"$CURRENT_BOOT"'","previous_boot_ts":'"$LAST_KNOWN"'}'
    else
        echo "STATUS: REBOOTED — System rebooted at $CURRENT_BOOT"
    fi
    exit 1
else
    if [ "$JSON_OUT" = "1" ]; then
        echo '{"status":"CLEAN","boot_time":"'"$CURRENT_BOOT"'"}'
    else
        echo "STATUS: CLEAN — No reboot since last check (boot: $CURRENT_BOOT)"
    fi
    exit 0
fi


Security scan verdicts — ClawScan: clean | static analysis: clean | VirusTotal: clean | SkillSpector: clean (LOW)