diff --git a/noct_sftp_copy.sh b/noct_sftp_copy.sh index 045a932..7690fa0 100644 --- a/noct_sftp_copy.sh +++ b/noct_sftp_copy.sh @@ -1,3 +1,10 @@ + +declare -A FILE_DEST_MAP=( + ["noct_fxdcf*.csv"]="/app/tyquant/deploy/kxinstall/delta-data/fileStore/fileUpload/noctData/dailyCashFlow" + ["noct_evrFxRate*.csv"]="/app/tyquant/deploy/kxinstall/delta-data/fileStore/fileUpload/noctData/EVRFxRate" + ["noct_fxtv*.csv"]="/app/tyquant/deploy/kxinstall/delta-data/fileStore/fileUpload/noctData/transactionView" + +) #!/bin/bash # ============================================================================= # Script: noct_sftp_copy.sh @@ -6,7 +13,7 @@ # a specified user. Designed for silent cron execution with # full logging on Red Hat Enterprise Linux. # Cron example (runs daily at 02:00 as root): -# 0 2 * * * /path/to/noct_sftp_copy.sh +# 0 2 * * * /usr/local/bin/noct_sftp_copy.sh # ============================================================================= # --- Configuration ----------------------------------------------------------- @@ -23,12 +30,11 @@ declare -A FILE_DEST_MAP=( ["noct_fxdcf*.csv"]="/app/tyquant/deploy/kxinstall/delta-data/fileStore/fileUpload/noctData/dailyCashFlow" ["noct_evrFxRate*.csv"]="/app/tyquant/deploy/kxinstall/delta-data/fileStore/fileUpload/noctData/EVRFxRate" ["noct_fxtv*.csv"]="/app/tyquant/deploy/kxinstall/delta-data/fileStore/fileUpload/noctData/transactionView" - ) # Log file location and retention (days) LOG_FILE="/var/log/noct_sftp_copy.log" -LOG_RETAIN_DAYS=396 +LOG_RETAIN_DAYS=30 # ----------------------------------------------------------------------------- @@ -56,7 +62,7 @@ rotate_log() { # ----------------------------------------------------------------------------- -log "===== START copy_csv_files ============================================" +log "===== START noct_sftp_copy ============================================" # Prune old log entries rotate_log @@ -116,7 +122,7 @@ ERRORS=0 for pattern in "${!FILE_DEST_MAP[@]}"; do dest_dir="${FILE_DEST_MAP[$pattern]}" - # Expand the glob pattern to find the matching file(s) + # Expand the glob pattern to find all matching files matches=( "$SRC_DIR"/$pattern ) # Check if the glob returned any real matches @@ -126,12 +132,12 @@ for pattern in "${!FILE_DEST_MAP[@]}"; do continue fi - # Warn if multiple files match — only the first will be copied - if [[ ${#matches[@]} -gt 1 ]]; then - log "WARNING: Multiple files match pattern '$pattern' — only '$(basename "${matches[0]}")' will be copied" - fi + log "INFO: Found ${#matches[@]} file(s) matching pattern '$pattern'" - copy_and_chown "${matches[0]}" "$dest_dir" "$TARGET_USER" || (( ERRORS++ )) + # Copy all matching files to the destination + for src_file in "${matches[@]}"; do + copy_and_chown "$src_file" "$dest_dir" "$TARGET_USER" || (( ERRORS++ )) + done done if [[ $ERRORS -eq 0 ]]; then