9

Tip #363   Finding log files X number of days old and deleteing them.

This is a script that I recently wrote to find the logs of my IDP that were over 90 days old and delete them.

The script is pretty much self explanatory.

## Lets find the log directories that are over 90 Days old.
find /var/netscreen/DevSvr/logs -mtime +90 -type d -prune -print > /root/scripts/files-deleted

## Now let's log the directories we are going to delete.
touch /root/scripts/deletelog

## We want to know when the files were deleted so we will append that to the log file.
date >> /root/scripts/deletelog

## Now we go through and delete the directories that are over 90 days old
## and log the directories that we delete to the log file.
for FILE in `cat /root/scripts/files-deleted`
do
echo Deleting $FILE ... >> /root/scripts/deletelog
rm -Rf $FILE
done

## Finally we will email a copy of the log file to the admin for his/(or her) review.
cat /root/scripts/deletelog | mail -s "90 Day IDP log cleanup" youremailaddress@domian.com