72824cf680
export-healthcheck.sh inspects the ctrader-export systemd service result and today's export log, then sends a one-line Telegram summary via notify.sh. Intended to run a few hours after the 03:30 timer (e.g. a one-shot `systemd-run --user` timer) to confirm the overnight export actually ran.
42 lines
1.9 KiB
Bash
Executable File
42 lines
1.9 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
#
|
|
# Health check for the scheduled daily export (see deploy/systemd/). Inspects the
|
|
# systemd service result + today's export log and sends a one-line German Telegram
|
|
# summary via ~/.claude/notify.sh. Meant to be run a few hours after the 03:30 timer.
|
|
set -uo pipefail
|
|
export PATH="/usr/local/bin:/usr/bin:/bin"
|
|
|
|
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
|
LOG_DIR="$REPO_ROOT/runtime/logs"
|
|
notify() { "$HOME/.claude/notify.sh" "$1" >/dev/null 2>&1 || true; }
|
|
|
|
# 1. Was the timer ever installed?
|
|
if ! systemctl cat ctrader-export.service >/dev/null 2>&1; then
|
|
notify "cTrader-Check: Timer war NICHT installiert -> kein 3:30-Lauf. sudo-Install nachholen (deploy/systemd/README.md)."
|
|
exit 0
|
|
fi
|
|
|
|
result=$(systemctl show ctrader-export.service -p Result --value 2>/dev/null)
|
|
|
|
# 2. Did a run actually happen today? (cron-export.sh writes one log per run.)
|
|
todays_log=$(find "$LOG_DIR" -name 'export-*.log' -newermt 'today 00:00' 2>/dev/null | sort | tail -1)
|
|
if [[ -z "$todays_log" ]]; then
|
|
notify "cTrader-Check: Timer installiert, aber HEUTE kein Export-Log -> 3:30-Lauf fand nicht statt (Maschine um 3:30 aus? Service-Result=$result)."
|
|
exit 0
|
|
fi
|
|
|
|
logname=$(basename "$todays_log")
|
|
banner=$(grep "Done" "$todays_log" | tail -1)
|
|
aborts=$(grep -c "ABORT" "$todays_log" 2>/dev/null); aborts=${aborts:-0}
|
|
fresh=$(find /mnt/tickdata/Pepperstone -maxdepth 1 -name '*.m1' -newermt 'today 02:00' 2>/dev/null | wc -l)
|
|
|
|
# 3. Verdict
|
|
if (( aborts > 0 )); then
|
|
reason=$(grep "ABORT" "$todays_log" | tail -1 | sed 's/.*ABORT: //; s/ Stopping.*//')
|
|
notify "cTrader-Check: Lauf ABGEBROCHEN -> ${reason:-unbekannt} (Log $logname)."
|
|
elif [[ -n "$banner" ]]; then
|
|
notify "cTrader-Check: 3:30-Lauf OK -- ${banner##*— } | $fresh frische Dateien."
|
|
else
|
|
notify "cTrader-Check: Lauf unklar (Result=$result, $fresh frische Dateien) -- Log $logname pruefen."
|
|
fi
|