shutdown-notify

This commit is contained in:
Christoph J. Scherr 2024-10-29 01:59:11 +01:00
parent 45fd2e35d5
commit 6966d6fc1f
1 changed files with 28 additions and 0 deletions

28
shutdown-notify Executable file
View File

@ -0,0 +1,28 @@
#!/bin/bash
set -euo pipefail # Strikte Fehlerbehandlung
# Check für Parameter
if [ -z "$1" ]; then
echo "Usage: $0 <minutes>"
exit 1
fi
MINS="$1" # Quote für safety
CREDS=$(cat /root/secret/ntfy.txt || exit 1) # Explizites error handling
# Sende Notification
if ! curl -f -s \
-u "$CREDS" \
-d "Homeserver fährt in $MINS Minuten runter." \
-H "Title: Server Shutdown" \
-H "Priority: high" \
https://ntfy.sh/homeserver-shutdown; then
echo "Failed to send notification"
exit 1
fi
# Warte auf Zustellung
sleep 5
# Führe Shutdown aus
shutdown "$MINS"