Thursday, November 14, 2013

Making Sure Logs Don't Get Out of Control


Sometimes, you need a little script to make sure your logs aren't getting too crazy. Enjoy!

#! /bin/bash

###################################################################
#
# Author: Matthew Myrick
# Date Created: 20120330
# Date Modified: 20120330
# Purpose: This scripts is used to remove old data when the
#       disk is over 97% full
#
# Dependencies: CRON
#
####################################################################

#CHECK TO SEE DISK USE PERCENTAGE
perc="`df -h /Promise | tail --lines 1 | awk '{print $5}' | cut -d '%' -f 1`"

#COMPARE VALUE TO OUR LIMIT
if [ "$perc" -gt "97" ]; then
 /usr/bin/find /Promise -maxdepth 1 -type d -printf "%T@ %p \n" | sort -n -k 1,1 | awk '{print $2}' | head -1 | xargs rm -rf
fi

1 comment:

  1. Need just a script to delete files older than 30 days???
    find /file/path/ -maxdepth 1 -mtime +30 -name finename__\* -exec rm -rf {} \;

    ReplyDelete