请大牛帮忙解答shell的意思
首先是crontab的意思
0 3 1 * * /root/scripts/sweep_apache_log > /root/logs/sweep_apache_log.log 2>&1
# define saving days
SAVING_DAYS=90
# define log directory
LOG_DIR=/var/log/httpd
ACCESS_PREFIX='access.'
ERROR_PREFIX='error.'
LOG_SUFFIX='.log'
# compose archive file name
# 获取两个月之前的月份,比如 201311
lastmonth=`date +%Y%m -d '2 months ago'`
# 处理 Apache 的 access log 和 error log
for prefix in $ACCESS_PREFIX $ERROR_PREFIX ; do
# 设置归档日志的名字,比如 access201311.log
arcfile=${LOG_DIR}/${prefix}${lastmonth}.log
# already archived?
if [ -f ${arcfile} ]; then
# 对于已经做过归档的日志,直接进行压缩
gzip -9 ${arcfile}
echo 'logs are already archived, but they are not compressed'
continue
fi
if [ -f ${arcfile}.gz ]; then
echo 'logs are already sweeped'
continue
fi
# ok, trying to cat them and then gzip it
cat ${LOG_DIR}/${prefix}${lastmonth}*${LOG_SUFFIX} > ${arcfile}
gzip -9 ${arcfile}
# delete individual logs
rm -f ${LOG_DIR}/${prefix}${lastmonth}*${LOG_SUFFIX}
# end of for
done
# delete old archive files
find ${LOG_DIR} -type f -name '*.gz' -mtime +${SAVING_DAYS} -exec rm -f {} \;
# EOF