From 94b359fded8c1f6467d14bd54e1180b5f3fd04a9 Mon Sep 17 00:00:00 2001 From: DragonSlayer_14 Date: Thu, 6 Mar 2025 10:37:27 +0100 Subject: [PATCH] =?UTF-8?q?Feat:=20F=C3=BCgt=20=C3=9Cberpr=C3=BCfung=20auf?= =?UTF-8?q?=20interaktive=20Shell=20hinzu.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Utility/IsInteractive.sh | 8 ++++++++ Utility/Log.sh | 12 +++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 Utility/IsInteractive.sh diff --git a/Utility/IsInteractive.sh b/Utility/IsInteractive.sh new file mode 100644 index 0000000..40390af --- /dev/null +++ b/Utility/IsInteractive.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +is_interactive() { + case $- in + *i*) return 1 ;; # Interaktive Shell + *) return 0 ;; # Nicht-interaktive Shell + esac +} diff --git a/Utility/Log.sh b/Utility/Log.sh index c0f25e6..11a8f6d 100755 --- a/Utility/Log.sh +++ b/Utility/Log.sh @@ -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 - echo "$(date +'%Y-%m-%d %H:%M:%S') - $1" | tee -a "$LOGFILE" >/dev/tty + 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 }