Feat: Fügt Überprüfung auf interaktive Shell hinzu.

This commit is contained in:
DragonSlayer_14 2025-03-06 10:37:27 +01:00
parent 69b8a914ca
commit 94b359fded
2 changed files with 19 additions and 1 deletions

8
Utility/IsInteractive.sh Normal file
View File

@ -0,0 +1,8 @@
#!/bin/bash
is_interactive() {
case $- in
*i*) return 1 ;; # Interaktive Shell
*) return 0 ;; # Nicht-interaktive Shell
esac
}

View File

@ -1,5 +1,9 @@
#!/bin/bash
# === IMPORTS ===
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "$SCRIPT_DIR/IsInteractive.sh"
# === Variablen ===
LOGDIR="/tmp/skript-logs"
LOGFILE="$LOGDIR/$(basename "$0" .sh)_$(date +'%Y-%m-%d').log"
@ -13,5 +17,11 @@ log() {
touch "$LOGFILE"
fi
if is_interactive; then
# Interaktive Shell
echo "$(date +'%Y-%m-%d %H:%M:%S') - $1" | tee -a "$LOGFILE" >/dev/tty
else
# Crontab oder nicht-interaktive Umgebung
echo "$(date +'%Y-%m-%d %H:%M:%S') - $1" >>"$LOGFILE"
fi
}