make log file destination configurable
This commit is contained in:
@@ -18,3 +18,6 @@ MAXBAK=3
|
||||
|
||||
# SSH key
|
||||
#SSH_KEY="~/.ssh/mykey_rsa"
|
||||
|
||||
# Logfile. Default: $CURDIR/backup.log
|
||||
# LOG_FILE=/var/log/uberspace-backup.log
|
||||
|
||||
@@ -15,6 +15,9 @@ set -Eeuo pipefail
|
||||
# Set correct UTF-8 encoding (for FreeBSD jail)
|
||||
export LC_ALL=en_US.UTF-8
|
||||
|
||||
# Initialise variables
|
||||
LOG_FILE=
|
||||
|
||||
CURDIR=$(dirname "$(readlink -f "$0")")
|
||||
if [ ! -e "$CURDIR"/config.cfg ]; then echo "Missing config.cfg file. Edit and rename config.cfg.sample"; exit 1; fi
|
||||
source "$CURDIR"/config.cfg
|
||||
@@ -29,9 +32,13 @@ else
|
||||
SSH_KEY=~/.ssh/id_rsa
|
||||
fi
|
||||
|
||||
if [ -z "${LOG_FILE}" ]; then
|
||||
# defaults
|
||||
LOG_FILE="$CURDIR"/backup.log
|
||||
fi
|
||||
|
||||
# Get current date
|
||||
DATE=$(date +"%Y-%m-%d_%H-%M")
|
||||
LOG="$CURDIR"/backup.log
|
||||
|
||||
function trim {
|
||||
sed -r -e 's/^[[:space:]]*//g' -e 's/[[:space:]]*$//g'
|
||||
@@ -43,7 +50,7 @@ function pdate {
|
||||
function logecho {
|
||||
# Echo string and copy it to log while attaching the current date
|
||||
echo "$(pdate) $*"
|
||||
echo "$(pdate) $*" >> "$LOG"
|
||||
echo "$(pdate) $*" >> "$LOG_FILE"
|
||||
}
|
||||
|
||||
# Loop over all hosts
|
||||
|
||||
Reference in New Issue
Block a user