From 65cd4e77bf6e9e92dd42543d92a3c8432176a26e Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Fri, 9 Feb 2018 16:09:13 -0500 Subject: [PATCH] JBAS-1975 Merge latest adp file mgt script changes Signed-off-by: Bill Erickson --- KCLS/admin-scripts/adp-file-mgmt.sh | 101 +++++++++++++++++++++++++++++------- 1 file changed, 81 insertions(+), 20 deletions(-) diff --git a/KCLS/admin-scripts/adp-file-mgmt.sh b/KCLS/admin-scripts/adp-file-mgmt.sh index bd745ec3c0..c921282881 100755 --- a/KCLS/admin-scripts/adp-file-mgmt.sh +++ b/KCLS/admin-scripts/adp-file-mgmt.sh @@ -1,14 +1,20 @@ #!/bin/bash +# Author: Bill Erickson +# +# Script for archiving ADP employee files and notifying KCLS +# and ADP staff when files are not present. set -ueo pipefail BASE_PATH=/home/sftpadp/pending/ PROC_PATH="$BASE_PATH/Processed" MAIL_CMD=mailx MAIL_RECIP=bserickson@kcls.org,dbebeling@kcls.org,smylavarapu@kcls.org,itsopsalert@kcls.org -#MAIL_RECIP=bserickson@kcls.org +ADP_RECIP=northwestservice@adp.com CURRENT_YMD=$(date +'%F'); -COMPRESS_AGE="6" -DELETE_AGE="365" +COMPRESS_AGE="6" # zip files older than this many days +DELETE_AGE="365" # delete files older than this many days +TEST_MODE="" +STAGE=""; FILES=(AllEmployees.csv TerminatedEmployees.csv) @@ -18,11 +24,12 @@ function announce { ERROR_MESSAGES="" function report { - ERROR_MESSAGES="$ERROR_MESSAGES$(date +'%F %T') $1\n" + #ERROR_MESSAGES="$ERROR_MESSAGES$(date +'%F %T') $1\n" + ERROR_MESSAGES="$ERROR_MESSAGES$1\n" announce "$1" } -# email import summary output +# email summary report function report_results { if [ ! "$(which $MAIL_CMD)" ]; then @@ -33,28 +40,82 @@ function report_results { return; fi - echo -e "$ERROR_MESSAGES" | $MAIL_CMD \ - -s "ADP File Error [$(date +'%F')]" $MAIL_RECIP + if [ $STAGE == 1 ]; then + SUBJECT="ADP File Error [KCLS $(date +'%F')]" + # stage-1 failures also notify ADP + [ -z "$TEST_MODE" ] && MAIL_RECIP="$MAIL_RECIP,$ADP_RECIP" + ERROR_MESSAGES=" +Hi ADP Team,\n +We did not receive the the following files today at 1pm. Please verify and get back to us.\n +$ERROR_MESSAGES" + else + SUBJECT="ADP File 2nd Check [$(date +'%F')]" + fi + + echo -e "$ERROR_MESSAGES" | $MAIL_CMD -s "$SUBJECT" $MAIL_RECIP } -cd $BASE_PATH; +function check_files { -for FILE in "${FILES[@]}"; do - if [ -f "$FILE" ]; then - announce "Found file $FILE"; + for FILE in "${FILES[@]}"; do BASE_FILE="${FILE%.*}" - mv $FILE "$PROC_PATH/$BASE_FILE.$CURRENT_YMD.csv" - else - report "$FILE NOT FOUND!"; - fi; + DEST_FILE="$PROC_PATH/$BASE_FILE.$CURRENT_YMD.csv" + + if [ $STAGE == 2 -a -f $DEST_FILE ]; then + # File already archived. Nothing to do. + continue + fi + + if [ -f "$FILE" ]; then + if [ $STAGE == 1 ]; then + announce "Found file $FILE"; + else + # Always report file disposition in stage 2. + report "$FILE : Found"; + fi; + mv $FILE $DEST_FILE + else + report "$FILE : NOT Found"; + fi; + done; +} + +function cleanup_files { + + # Delete files older than DELETE_AGE + /usr/bin/find $PROC_PATH -type f -mtime +$DELETE_AGE -delete + + # Compress files older than COMPRESS_AGE + /usr/bin/find $PROC_PATH -type f -mtime +$COMPRESS_AGE \ + -not -name "*zip" -exec /usr/bin/zip -m {}.zip {} \; +} + +function usage { + cat <