I've built a simple SH script to run rsync to download media from my NAS to a local USB hard drive on a Raspberry Pi (want the hardware to be portable for when I travel for work...). This should have been straight forward but silly string concatenation is messing this up. See in line for where script is messing up:::
SOURCE_FOLDER="/storage/SHARED/MEDIA"
echo "Source folder to backup is: " $SOURCE_FOLDER
TARGET_FOLDER="/var/media/USB2TB"
echo "Target folder parent folder is: " $TARGET_FOLDER
CURRENT_SCRIPT_NAME_FQDN=$(readlink -f $0)
echo "Current script FQDN is: " $CURRENT_SCRIPT_NAME_FQDN
CURRENT_SCRIPT_NAME_PATH=$(dirname $CURRENT_SCRIPT_NAME_FQDN)
echo "Current script path is: " $CURRENT_SCRIPT_NAME_PATH
CURRENT_SCRIPT_FULL_NAME=$(basename $CURRENT_SCRIPT_NAME_FQDN)
echo "Current script full name is: " $CURRENT_SCRIPT_FULL_NAME
CURRENT_SCRIPT_NAME="${CURRENT_SCRIPT_FULL_NAME%.*}"
echo "Current script name is: " $CURRENT_SCRIPT_NAME
LOG_FILE_TIME=$(date +"%Y%m%d%H%M%S")
echo "Log file time is: " $LOG_FILE_TIME
LOG_FILE_EXTENSION=".log"
echo "Log file extension is: " $LOG_FILE_EXTENSION
LOG_FILE_DELIMITER="_"
echo "Log file delimiter is: " $LOG_FILE_DELIMITER
# ISSUES HERE:
LOG_FILE_NAME="${CURRENT_SCRIPT_NAME}${LOG_FILE_DELIMITER}${LOG_FILE_TIME}${LOG_FILE_EXTENSION}"
echo "Log file name is: $LOG_FILE_NAME"
# This is expected to return "MIRROR-MEDIA_20191002135123.log" but does NOT!
# AND ISSUES HERE:
LOG_FILE_FQDN="$CURRENT_SCRIPT_NAME_PATH/$LOG_FILE_NAME"
echo "Log file FQDN is: " $LOG_FILE_FQDN
# This is expected to return "/var/media/USB2TB/MIRROR-MEDIA_20191002135123.log" but does NOT!
# rsync -avzn $SOURCE_FOLDER $TARGET_FOLDER
# rsync --log-file=$LOG_FILE_FQDN -avz --delete $SOURCE_FOLDER $TARGET_FOLDER