Update noct_sftp_copy.sh

This commit is contained in:
2026-04-18 16:51:24 +01:00
parent ecd087d1f8
commit c2caed604e
+16 -10
View File
@@ -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 #!/bin/bash
# ============================================================================= # =============================================================================
# Script: noct_sftp_copy.sh # Script: noct_sftp_copy.sh
@@ -6,7 +13,7 @@
# a specified user. Designed for silent cron execution with # a specified user. Designed for silent cron execution with
# full logging on Red Hat Enterprise Linux. # full logging on Red Hat Enterprise Linux.
# Cron example (runs daily at 02:00 as root): # 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 ----------------------------------------------------------- # --- Configuration -----------------------------------------------------------
@@ -23,12 +30,11 @@ declare -A FILE_DEST_MAP=(
["noct_fxdcf*.csv"]="/app/tyquant/deploy/kxinstall/delta-data/fileStore/fileUpload/noctData/dailyCashFlow" ["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_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" ["noct_fxtv*.csv"]="/app/tyquant/deploy/kxinstall/delta-data/fileStore/fileUpload/noctData/transactionView"
) )
# Log file location and retention (days) # Log file location and retention (days)
LOG_FILE="/var/log/noct_sftp_copy.log" 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 # Prune old log entries
rotate_log rotate_log
@@ -116,7 +122,7 @@ ERRORS=0
for pattern in "${!FILE_DEST_MAP[@]}"; do for pattern in "${!FILE_DEST_MAP[@]}"; do
dest_dir="${FILE_DEST_MAP[$pattern]}" 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 ) matches=( "$SRC_DIR"/$pattern )
# Check if the glob returned any real matches # Check if the glob returned any real matches
@@ -126,12 +132,12 @@ for pattern in "${!FILE_DEST_MAP[@]}"; do
continue continue
fi fi
# Warn if multiple files match — only the first will be copied log "INFO: Found ${#matches[@]} file(s) matching pattern '$pattern'"
if [[ ${#matches[@]} -gt 1 ]]; then
log "WARNING: Multiple files match pattern '$pattern' — only '$(basename "${matches[0]}")' will be copied"
fi
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 done
if [[ $ERRORS -eq 0 ]]; then if [[ $ERRORS -eq 0 ]]; then