@@ -40,6 +40,7 @@ LOG_RETENTION_DAYS=30
4040
4141LOGGER_TAG=" cloud-image-downloader"
4242LOGGER_FACILITY=" user"
43+ LOGGER_AVAILABLE=false
4344
4445log_message () {
4546 local priority=$1
@@ -48,10 +49,12 @@ log_message() {
4849 local timestamp=$( date +' %Y-%m-%d %H:%M:%S' )
4950
5051 # Log to file
51- echo " ${timestamp} [${priority} ] ${message} ” | tee ${LOG_FILE}
52+ echo " ${timestamp} [${priority} ] ${message} " | tee -a " ${LOG_FILE} "
5253
5354 # Log to syslog using logger utility
54- logger -t " ${LOGGER_TAG} " -p " ${LOGGER_FACILITY} .${priority} " -- " ${message} "
55+ if [ " ${LOGGER_AVAILABLE} " = true ]; then
56+ logger -t " ${LOGGER_TAG} " -p " ${LOGGER_FACILITY} .${priority} " -- " ${message} "
57+ fi
5558}
5659
5760log_info () {
@@ -154,14 +157,14 @@ cleanup_on_exit() {
154157 fi
155158}
156159
157- trap cleanup_on_exit EXIT INT TER
160+ trap cleanup_on_exit EXIT INT TERM
158161
159162# -------------------------------------------------------------------------------
160163# Main Script Logic
161164# -------------------------------------------------------------------------------
162165
163- if ! command -v logger &> /dev/null; then
164- log_warn " logger utility not found - syslog logging disabled "
166+ if command -v logger & > /dev/null; then
167+ LOGGER_AVAILABLE=true
165168fi
166169
167170# Ensure base destination and log directories exist
@@ -176,6 +179,13 @@ log_info "Temporary directory: $TEMP_DIR"
176179log_info " Base destination directory: $DEST_DIR "
177180log_info " Log file: $LOG_FILE "
178181
182+ # Inform about logger status
183+ if [ " ${LOGGER_AVAILABLE} " = true ]; then
184+ log_info " Syslog logging enabled (tag: ${LOGGER_TAG} )"
185+ else
186+ log_warn " Syslog logging disabled - logger utility not found"
187+ fi
188+
179189# Loop through the image URLs
180190for filename in " ${! IMAGE_URLS[@]} " ; do
181191 url=" ${IMAGE_URLS[$filename]} "
0 commit comments