30 1 * * * /ecapp/soft/ECShellScript/clean/clean.sh >> /ecapp/soft/ECShellScript/clean/logs/clean.`date +\%Y-\%m-\%d`.log 2>&1
ls -lR /ecapp/soft|grep ‘^/ecapp/soft‘|grep -E "\/logs:$"
[ecwbs@ecapp90 clean]$ cat cleanlist
/ecapp/soft/ECShellScript/clean/logs
/ecapp/soft/zabbix_agent/logs
[ecwbs@ecapp91 clean]$ cat clean.sh
#!/bin/sh
echo "cleaning logs start......"
filepath="/ecapp/soft/ECShellScript/clean/cleanlist"
for fs in $( cat $filepath )
do
echo "clean "$fs
find $fs -name \*20*.gz -mtime +30 -exec rm {} \;
done
for fz in $( cat $filepath )
do
echo "gzip "$fz
find $fz -name \*20*[a-y,0-9] -type f -mtime +1 -exec /usr/bin/gzip -9 {} \;
done
exit 0
ls -lR /apache|grep ‘^/apache‘|grep -E "\/logs:$"
30 1 * * * /apache/ECShellScript/clean/clean.sh >> /apache/ECShellScript/clean/logs/clean.`date +\%Y-\%m-\%d`.log 2>&1
[ecwbl01@secweb3 clean]$ cat clean.sh
#!/bin/sh
echo "cleaning logs start......"
filepath="/apache/ECShellScript/clean/cleanlist"
for fs in $( cat $filepath )
do
echo "clean "$fs
find $fs -name \*20*.gz -mtime +30 -exec rm {} \;
done
for fz in $( cat $filepath )
do
echo "gzip "$fz
find $fz -name \*20*[a-y,0-9] -type f -mtime +1 -exec /usr/bin/gzip -9 {} \;
done
exit 0
原文:https://www.cnblogs.com/charon2/p/10349810.html