cron + logrotate 日志切割

2024-03-18  本文已影响0人  明明就_c565

cron配置

vim /etc/cron.hourly/logrotate

#!/bin/sh

/usr/sbin/logrotate /etc/logrotate.d/cmp

EXITVALUE=$?

if [ $EXITVALUE != 0 ]; then

    /usr/bin/logger -t logrotate "ALERT exited abnormally with [$EXITVALUE]"

fi

exit 0

logrotate配置

/etc/logrotate.d/cmp

/var/log/app/*/*.log {

    su root root

    daily

    rotate 180

    size 50M

    compress

    delaycompress

    missingok

    notifempty

    dateext

    dateformat -%Y%m%d.%s

}

crontab服务

启动

systemctl status crond

systemctl start crond

systemctl ebable crond

上一篇下一篇

猜你喜欢

热点阅读