#!/bin/bash
DEST="/var/lib/mysql/"
Num=2
################# keep the data amount ####################################
if [ `find $DEST -name '*bin.0*' | cut -d '/' -f5 | grep -v 'relay' | sort | wc -l` -gt $Num ];then
while [ `find $DEST -name '*bin.0*' | cut -d '/' -f5 | grep -v 'relay' | sort | wc -l` -gt $Num ]
do
# echo "deling"
BINLOG=`find $DEST -name '*bin.*' | cut -d '/' -f5 | grep -v 'relay' | grep -v 'index' | sort | head -n1 `
rm -rf $DEST$BINLOG
# echo $DEST$BINLOG
done
fi