From 1b9994d09dfc822f421441630712155d46968dfb Mon Sep 17 00:00:00 2001 From: Ducky Date: Mon, 1 Apr 2024 23:20:42 +0100 Subject: [PATCH] various --- usr/local/bin/sh.zio.backup | 6 +++++- usr/local/libexec/zio/helpers/bash.sh | 12 ++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/usr/local/bin/sh.zio.backup b/usr/local/bin/sh.zio.backup index d794890..9082e9d 100755 --- a/usr/local/bin/sh.zio.backup +++ b/usr/local/bin/sh.zio.backup @@ -128,7 +128,11 @@ function invoke_script() { exec 3>&1 script_error_log="$(create_tmp_file)" - script_output=$("$backup_scripts_dir/$backup_script_filename" 2>$script_error_log 2>&1 | tee /dev/fd/3) + script_output=$("$backup_scripts_dir/$backup_script_filename" 2>$script_error_log | tee /dev/fd/3) + + if [[ -f "$script_error_log" ]]; then + cat "$script_error_log" + fi if [[ "$?" == 0 ]]; then trigger_notify "success" "Backup script succeeded: $backup_script_name" "..." diff --git a/usr/local/libexec/zio/helpers/bash.sh b/usr/local/libexec/zio/helpers/bash.sh index fa06913..3e70a6a 100644 --- a/usr/local/libexec/zio/helpers/bash.sh +++ b/usr/local/libexec/zio/helpers/bash.sh @@ -8,7 +8,7 @@ function create_log() { content="$1" log_dir="/var/log/zio" - log_file="$(date +%Y%m%d%H%M%S).$(echo $RANDOM | md5sum | head -c 6; echo;).log" + log_file="$(get_random_filename).log" if [[ ! $(id -u) = 0 ]]; then log_dir="/tmp/zio/logs" @@ -24,7 +24,11 @@ function create_log() { function create_tmp_file() { name="$1" prefix_dir="/tmp/zio" - tmp_path="$prefix_dir/$(date +%s).$name" + tmp_path="$prefix_dir/$(get_random_filename)" + + if [[ "$name" != "" ]]; then + tmp_path+=".$name" + fi mkdir -p "$prefix_dir" touch "$tmp_path" @@ -59,6 +63,10 @@ function get_config_dir() { echo "$config_dir" } +function get_random_filename() { + echo "$(date +%Y%m%d%H%M%S).$(echo $RANDOM | md5sum | head -c 6; echo;)" +} + function get_real_path() { echo "$(cd -P "$1" && pwd)" }