Shell script to delete logs older than 7 days – daily

| June 6, 2011 | 0 Comments

Script in cron to delete logs daiily older then 7 days ( excludding current day )

serverunix# crontab -l | grep /scripts/cleanup-dailys
5 6 * * 1-5 /scripts/cleanup-dailys > /dev/null 2>&1

serverunix#cat cleanup-dailys
find /data/logs/dailys -type f -mtime +6 -exec ls -l {} \; | tee -a $LOGFILE
find /data/logs/dailys -type f -mtime +6 -exec /usr/contrib/bin/gzip {} \;
find /data/logs/dailys -type f -mtime +6 -exec rm -rf {} \;

Tags: ,

Category: Shell Scripting

Leave a Reply

You must be logged in to post a comment.