From 6966d6fc1f8f8ee7bdb6b293cdae4445640d014c Mon Sep 17 00:00:00 2001 From: PlexSheep Date: Tue, 29 Oct 2024 01:59:11 +0100 Subject: [PATCH] shutdown-notify --- shutdown-notify | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100755 shutdown-notify diff --git a/shutdown-notify b/shutdown-notify new file mode 100755 index 0000000..d4f1391 --- /dev/null +++ b/shutdown-notify @@ -0,0 +1,28 @@ +#!/bin/bash +set -euo pipefail # Strikte Fehlerbehandlung + +# Check für Parameter +if [ -z "$1" ]; then + echo "Usage: $0 " + 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"