1. First is to create a file, say SUBDIR.txt with the ff. contents:
MERGE/REJECTS/ARCHIVE
MERGE/REJECTS/ARCHIVERAW
MERGE/FILTERED/ARCHIVE
MERGE/FILTERED/ARCHIVERAW
INSERT/REJECTS/INSERTED
INSERT/FILTERED/INSERTED
FTP/FTP_ARCHIVE
2. I made two variations of the script:
a. Version 1
#!/bin/bash
export LOGDIR=/ramsys_data/bmcps/ramsys/
export DIRLIST="ALTL AMA5 CAMA FREE NRTL SEGR UTSS"
for XXX in DIRLIST
do
cd $LOGDIR
if [ "$PWD" = "$LOGDIR" ]
then
for PURDIR in `cat SUBDIR.txt`
do
# A log file can be added here [good practice] to list the files to be deleted...
find $XXX/$PURDIR -type f -name "*" -mtime +5 -exec rm {} \;
done
else
echo "Check $USER\'s permissions; cannot change to $CURDIR."
# You can add a mailer here for notification...
exit 1
fi
done
b. Version 2
#!/bin/bash
LOGDIR=/ramsys_data/bmcps/ramsys/
DIRLIST="ALTL AMA5 CAMA FREE NRTL SEGR UTSS"
cd $LOGDIR || {
echo "Check the permissions; can't change to $CURDIR."
# You can add a mailer here for notification...
exit 1
}
for XXX in DIRLIST
do
for PURDIR in `cat SUBDIR.txt`
do
# A log file can be added here [good practice] to list the files to be deleted...
find $XXX/$PURDIR -type f -name "*" -mtime +5 -exec rm {} \;
done
done
If this will be run in cron, e.g. everyday at 0100H, we can make it as:
0 1 * * * ( scriptname_here.sh > /if_wanted/can/store/to/logfile 2>&1 ) &
Or throw it to /dev/null. Whatever suits you.
No comments:
Post a Comment