From ce74077859058e25c3a49044fd26cc73f651f115 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Fri, 9 Feb 2018 16:09:50 -0500 Subject: [PATCH] JBAS-1975 Archive ADPToJDE files same as ADP Signed-off-by: Bill Erickson --- KCLS/admin-scripts/jde-file-mgmt.sh | 122 ++++++++++++++++++++++++++++++++++++ 1 file changed, 122 insertions(+) create mode 100755 KCLS/admin-scripts/jde-file-mgmt.sh diff --git a/KCLS/admin-scripts/jde-file-mgmt.sh b/KCLS/admin-scripts/jde-file-mgmt.sh new file mode 100755 index 0000000000..ad57fa1605 --- /dev/null +++ b/KCLS/admin-scripts/jde-file-mgmt.sh @@ -0,0 +1,122 @@ +#!/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/JDE +PROC_PATH="$BASE_PATH/Processed" +MAIL_CMD=mailx +MAIL_RECIP=bserickson@kcls.org,dbebeling@kcls.org +#MAIL_RECIP=bserickson@kcls.org,dbebeling@kcls.org,smylavarapu@kcls.org,itsopsalert@kcls.org +#ADP_RECIP=northwestservice@adp.com +CURRENT_YMD=$(date +'%F'); +COMPRESS_AGE="6" # zip files older than this many days +DELETE_AGE="365" # delete files older than this many days +TEST_MODE="" +STAGE=""; + +FILES=(ADPtoJDE.csv) + +function announce { + echo "$(date +'%F %T') $(hostname): $1" +} + +ERROR_MESSAGES="" +function report { + #ERROR_MESSAGES="$ERROR_MESSAGES$(date +'%F %T') $1\n" + ERROR_MESSAGES="$ERROR_MESSAGES$1\n" + announce "$1" +} + +# email summary report +function report_results { + + if [ ! "$(which $MAIL_CMD)" ]; then + return; + fi + + if [ -z "$ERROR_MESSAGES" ]; then + return; + fi + + if [ $STAGE == 1 ]; then + SUBJECT="ADPtoJDE 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.\n +$ERROR_MESSAGES" + else + SUBJECT="ADP2JDE File 2nd Check [$(date +'%F')]" + fi + + echo -e "$ERROR_MESSAGES" | $MAIL_CMD -s "$SUBJECT" $MAIL_RECIP +} + +function check_files { + + for FILE in "${FILES[@]}"; do + BASE_FILE="${FILE%.*}" + 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 <