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
alias aptitude at awk bash bc cal cat cd colrm comm cp csh curl cut date dd df dialog diff dirname dpkg du fc find fuser grep gs gzip history iconv kill ksh last less ln ls lsof lynx m4 md5sum mkdir mkfifo mkisofs mv mysql nc netstat openssl OSX perl ping popd ps pushd python read redirection rm scp screen sed sort ssh stat sudo svn tail tar tee test top tr uniq vim wc wget xargs