shell 命令 find
程序员文章站
2022-04-30 17:17:36
...
deal_log.sh
deal_file.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