shell 命令 find

deal_log.sh

#! /bin/bash
find /home/*/* -maxdepth 4  -regex ".+\(\.log\|catalina\.out\)\(\.[\d\-]*\)?" -exec ./deal_file.sh {} \; 
find /opt/logs -type f -regex ".+\.log\(\.[0-9\-]*\)?" -exec ./deal_file.sh {} \; 




deal_file.sh
#! /bin/bash
logfile="clean_log.`date  +%Y-%m-%d`"
curfile=$1
if  ( echo "$curfile" | grep -e '\.log$' -e 'catalina\.out$' > /dev/null ) ;
then
size=`du -h $1 | awk '{ print $1 } '`
echo "" > $1
echo "clean file "$1 "size:" `du -h $1 | awk '{ print $1 } '`" old size:"$size >> $logfile;
else
echo "rm file" $1 `du -h $1 | awk '{ print $1 } '` >> $logfile;
rm -v $1
fi


你可能感兴趣的:(shell)