日期:2014-05-16  浏览次数:20604 次

请大牛帮忙解答shell的意思
首先是crontab的意思


0 3 1 * * /root/scripts/sweep_apache_log > /root/logs/sweep_apache_log.log 2>&1


然后是sweep_apache_log的内容了


# 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
lastmonth=`date +%Y%m -d '2 months ago'`

for prefix in $ACCESS_PREFIX $ERROR_PREFIX ; do
        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


我大概知道这个是来删除过期的log文件的,可是具体就不知道是怎么一个流程了,希望大牛帮忙解答
万分感谢!

------解决方案--------------------

0 3 1 * * /root/script