Im becoming desperate when debugging my script, I used some constructions recommended to me from my senior collegue and I dont know how to make it work properly.
#!/bin/bash -x
set -ueo pipefail
exec &>/tmp/dq.log
source ${BASH_SOURCE%/*}/env-prd.sh
times=${2:-1}
sleep=${3:-1}
name="all-dq_hourly"
fs_lock_file="/tmp/mwa/jobs/prd-${name}.lock"
( flock -n 200
log="/var/log/mwa/prd/$(date +%Y-%m-%d)__${name}.log"
for i in $(seq 1 $times); do
if [[ ! -f /tmp/stop ]]; then
couple commands
fi
sleep $sleep
done
) 200>"$fs_lock_file" | tee -a $log
rm $fs_lock_file
From the execs , I can see there is an issue with unbound variable for the tee -a $log part, couple commands get executed allright. I tried to use backtics in the log path, but to no benefit. I suspect the same issue with fs_lock_file, but I havent fixed the logging first yet.
Can somebody open my eyes and tell me what Im missing? Im not able to make the script logging to path specified.