免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 5997 | 回复: 7
打印 上一主题 下一主题

maillog 每天切割 疑问 postfix [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2010-05-25 11:57 |只看该作者 |倒序浏览
是这样的,因为工作需要 ,需要每天切割maillog日志。结果反复试验,不能成功,特发帖求救

系统本身是有日志切割的【每周4点零2分】
如下:
# uname -a
Linux wanganshi 2.6.18-92.el5PAE #1 SMP Tue Jun 10 19:22:41 EDT 2008 i686 i686 i386 GNU/Linux
# cat /etc/logrotate.d/syslog
/var/log/messages /var/log/secure /var/log/maillog /var/log/spooler /var/log/boot.log /var/log/cron {
    sharedscripts
    postrotate
        /bin/kill -HUP `cat /var/run/syslogd.pid 2> /dev/null` 2> /dev/null || true
        /bin/kill -HUP `cat /var/run/rsyslogd.pid 2> /dev/null` 2> /dev/null || true
    endscript
}
如上有了maillog 我理解是走下面这个文件默认切割的,如每周,轮询4个文件不压缩之类
# cat /etc/logrotate.conf
# see "man logrotate" for details
# rotate log files weekly
weekly
# keep 4 weeks worth of backlogs
rotate 4

# create new (empty) log files after rotating old ones
create

# uncomment this if you want your log files compressed
#compress

# RPM packages drop log rotation information into this directory
include /etc/logrotate.d

# no packages own wtmp -- we'll rotate them here
/var/log/wtmp {
    monthly
    minsize 1M
    create 0664 root utmp
    rotate 1
}
# cat /etc/crontab
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/

# run-parts
01 * * * * root run-parts /etc/cron.hourly
02 4 * * * root run-parts /etc/cron.daily
22 4 * * 0 root run-parts /etc/cron.weekly
42 4 1 * * root run-parts /etc/cron.monthly
默认每天的4点零2分会去执行cron.daily任务

现在的问题:
我将/etc/logrotae.conf中,weekly改为daily
因为要测试所以将
02 4 * * * root run-parts /etc/cron.daily
改为自定义时间如
08 12 * * * root run-parts /etc/cron.daily
问题是发现除了maillog之外的其他syslog 都进行了切割【再次尝试的时候会有如cron之类的不切割】
也重启了对应服务
sudo /etc/init.d/syslog restart
sudo /etc/init.d/crond restart

2 剔除了/etc/logrotate.d/syslog中/var/log/maillog部分
创建一个文件/etc/logratote.d/maillog,内容类似如下
/var/log/maillog {
daily
rotate 7
create 0600 root root
postrotate
        /bin/kill -HUP `cat /var/run/syslogd.pid 2> /dev/null` 2> /dev/null || true
        /bin/kill -HUP `cat /var/run/rsyslogd.pid 2> /dev/null` 2> /dev/null || true
        /bin/kill -HUP `cat /var/spool/postfix/pid/master.pid 2> /dev/null` 2> /dev/null || true
endscript
}
这样也是不能实现切割
请教对此应该如何处理 谢谢

论坛徽章:
0
2 [报告]
发表于 2010-05-25 14:47 |只看该作者
难道只能手动么
#!/bin/sh
/bin/mv /var/log/maillog /home/lxu/logbak/maillog-`date +%Y-%m-%d-%H-%M`
/bin/touch /var/log/maillog
/etc/rc.d/init.d/syslog restart
/etc/init.d/postfix reload

论坛徽章:
0
3 [报告]
发表于 2010-05-27 14:59 |只看该作者
实在不好用 还是写脚本解决了
/usr/sbin/logrotate -vf /root/maillog定时去强制解决
/var/log/maillog {
        daily
        missingok
        rotate 7
        nocompress
        copytruncate
        notifempty
        create 640 root root
}

论坛徽章:
34
亥猪
日期:2015-03-20 13:55:11戌狗
日期:2015-03-20 13:57:01酉鸡
日期:2015-03-20 14:03:56未羊
日期:2015-03-20 14:18:30子鼠
日期:2015-03-20 14:20:14丑牛
日期:2015-03-20 14:20:31辰龙
日期:2015-03-20 14:35:34巳蛇
日期:2015-03-20 14:35:56操作系统版块每日发帖之星
日期:2015-11-06 06:20:00操作系统版块每日发帖之星
日期:2015-11-08 06:20:00操作系统版块每日发帖之星
日期:2015-11-19 06:20:00黄金圣斗士
日期:2015-11-24 10:43:13
4 [报告]
发表于 2010-05-27 17:01 |只看该作者
syslog ?

论坛徽章:
0
5 [报告]
发表于 2010-05-28 19:17 |只看该作者
syslog ?
vermouth 发表于 2010-05-27 17:01

不太好使
后来强制执行就行 所以crontab强制执行了

论坛徽章:
34
亥猪
日期:2015-03-20 13:55:11戌狗
日期:2015-03-20 13:57:01酉鸡
日期:2015-03-20 14:03:56未羊
日期:2015-03-20 14:18:30子鼠
日期:2015-03-20 14:20:14丑牛
日期:2015-03-20 14:20:31辰龙
日期:2015-03-20 14:35:34巳蛇
日期:2015-03-20 14:35:56操作系统版块每日发帖之星
日期:2015-11-06 06:20:00操作系统版块每日发帖之星
日期:2015-11-08 06:20:00操作系统版块每日发帖之星
日期:2015-11-19 06:20:00黄金圣斗士
日期:2015-11-24 10:43:13
6 [报告]
发表于 2010-05-31 18:17 |只看该作者
回复 5# xuledw

怎么个强制法?

论坛徽章:
0
7 [报告]
发表于 2010-06-01 10:58 |只看该作者
这是我的邮件日志切割shell
#!/bin/bash

. /etc/profile

MailLog="maillog"
MailLogPath="/var/log"
DATE=`date -d yesterday +%Y%m%d`
Ipaddress=`ifconfig br0 | grep 'inet addr' | awk '{print $2}' | cut -d ':' -f 2`
CutMailLog=$MailLog.$Ipaddress.$DATE
           
cd $MailLogPath
mv $MailLog $CutMailLog
gzip -c  $CutMailLog > $CutMailLog.gz $CutMailLog && rm $CutMailLog -rf
/etc/init.d/syslog reload

# 删除5天前的日志
find /var/log/ -name "maillog.*.gz" -ctime +5 -exec rm -rf {} \;

论坛徽章:
0
8 [报告]
发表于 2015-02-02 00:18 |只看该作者
回复 1# xuledw

你好,我也现在也遇到这样的情况了,系统日志随着回滚日志一起滚动,这个问题你解决了吗?请指教下


   
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP