Cron / VPS

Cron job fail hoặc VPS down? Gửi alert tới điện thoại.

Backup, SSL, disk space và health checks nên báo lỗi mà không lộ token hoặc history.

Short answer

Dùng shell wrapper để chạy job, capture stderr, và gửi summary ngắn bằng nerve send khi job fail.

Đừng gửi full logs tới điện thoại. Gửi job name, host, exit code, timestamp và link dashboard hoặc runbook là đủ.

Wrapper script

#!/usr/bin/env sh
set -u

export NERVE_DSN="nerve://TOKEN:[email protected]"
LOG="/tmp/backup-cron.log"

if ! /opt/backup.sh >"$LOG" 2>&1; then
  {
    echo "cron failed: backup"
    echo "host=$(hostname)"
    echo "time=$(date -Is)"
    tail -20 "$LOG"
  } | nerve send --severity critical
fi

Crontab

0 2 * * * /usr/local/bin/backup-with-alert.sh

VPS and server checks

The same pattern works for disk space checks, SSL expiry checks, database backup jobs, systemd service health, and small VPS monitoring scripts.

Noise control

Add a cooldown if a job can fail repeatedly. One useful phone alert is better than fifty duplicate notifications while the same service is down.

Security boundary

Send-only secretSender DSN gửi encrypted signals vào một pipe. Nó không đọc history, không decrypt messages, và không execute commands.
No agent tokenAlerts thông thường không cần agent token. Agent chỉ dành cho signed bounded actions trên máy bạn tin tưởng.
Safe summarySend host, job name, exit code, and a short tail. Keep credentials out of alerts.

FAQ

Làm sao gửi GitHub Actions alert tới điện thoại?

Thêm step nerve send với if: failure() và lưu NERVE_DSN như GitHub Actions secret.

Sender DSN có đọc được alert cũ không?

Không. Sender DSN chỉ gửi encrypted signals vào một pipe.

Có cần chạy agent để nhận alerts không?

Không. Agent là tùy chọn cho signed actions trên máy tin tưởng.

Related