Feat: Fügt Überprüfung auf interaktive Shell hinzu.
This commit is contained in:
parent
69b8a914ca
commit
94b359fded
8
Utility/IsInteractive.sh
Normal file
8
Utility/IsInteractive.sh
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
is_interactive() {
|
||||||
|
case $- in
|
||||||
|
*i*) return 1 ;; # Interaktive Shell
|
||||||
|
*) return 0 ;; # Nicht-interaktive Shell
|
||||||
|
esac
|
||||||
|
}
|
||||||
@ -1,5 +1,9 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
# === IMPORTS ===
|
||||||
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
|
source "$SCRIPT_DIR/IsInteractive.sh"
|
||||||
|
|
||||||
# === Variablen ===
|
# === Variablen ===
|
||||||
LOGDIR="/tmp/skript-logs"
|
LOGDIR="/tmp/skript-logs"
|
||||||
LOGFILE="$LOGDIR/$(basename "$0" .sh)_$(date +'%Y-%m-%d').log"
|
LOGFILE="$LOGDIR/$(basename "$0" .sh)_$(date +'%Y-%m-%d').log"
|
||||||
@ -13,5 +17,11 @@ log() {
|
|||||||
touch "$LOGFILE"
|
touch "$LOGFILE"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if is_interactive; then
|
||||||
|
# Interaktive Shell
|
||||||
echo "$(date +'%Y-%m-%d %H:%M:%S') - $1" | tee -a "$LOGFILE" >/dev/tty
|
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
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user