Files
bash_utils/logger.sh
root 4c60127786 make local variables local
.. to not interfere with variables in the scripts that source these utils.
2025-02-03 11:12:05 +01:00

35 lines
828 B
Bash

#!/bin/bash
# https://stackoverflow.com/a/246128
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
. $SCRIPT_DIR/colors.sh
logger () {
echo -e "${NC}$(date) - [$BASHPID] - [${0##*/}] - $@${NC}"
}
loggerseparator () {
echo -e "${NC}$(date) - [$BASHPID] - ====================================="
}
saferun () {
local allcommands=""
for var in "$@"; do
allcommands="$allcommands$var /// "
done
logger "Enter to run the following command(s): $allcommands"
read ok
local ret=0
for var in "$@"; do
if [[ $ret -eq 0 ]]; then
$var
ret=$?
else
logger "command $var aborted because previous command exited non-zero!"
fi
done
loggerseparator
logger "Command(s) done!"
loggerseparator
}