skraps

logclean1.sh

Aug 19th, 2011
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.15 KB | None | 0 0
  1. # it removes entries older than 7 days from most common log files - having to add in qmail
  2. # and other formats also and have it run from a cron job.
  3.  
  4. skiplog="access_log  error_log bruteforceip rkhunter.log rkhunter.log.old anaconda.log brcm-iscsi.log datec2.sh datec.sh anaconda.syslog lastlog btmp dmesg lastlog mysqld.log rpmpkgs tallylog tallylog xferlog"
  5.  
  6. pathto="$?"
  7. logfiles="${?}*"
  8. match="0"
  9.  
  10. for d in $logfiles; do
  11. for c in $skiplog;do
  12.     echo "checking for matches of $c and $d"
  13.     b=`echo $d | sed 's/\// /g' | awk '{ print $3 }'`
  14.     echo "$d $c $b"
  15.     if [ "$c" == "$b" ];then
  16.         echo "skipping $b"
  17.         match="1"
  18.         break
  19.     else
  20.         match="0"
  21.     fi
  22. done
  23.  
  24.     if [ $match == "0" ];then
  25.         echo "processing $d"
  26.         while read line; do
  27.             date=`echo $line | awk '{ print $2 }'`
  28.             curdate=`date | awk '{ print $3 }'`
  29.             let "num1=10#${date}"
  30.             let "num2=10#${curdate}"
  31.            
  32.             if [ $num1 != "" ]; then
  33.                 math=$(( $num1 + 7 ))
  34.                 if [ $num1 == $num2 ] || [ $math -gt $num2 ];then
  35.                         echo $line >> ${d}.tmp
  36.                         echo $line
  37.                 fi
  38.                 if [ -e ${d}.tmp ];then
  39.                         mv ${d}.tmp ${d}
  40.                 fi
  41.             fi
  42.         done < $d
  43.         match=0
  44.         fi
  45. done
Advertisement
Add Comment
Please, Sign In to add comment