1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | # script monitor_fifo #!/usr/bin/perl # $fifo 为目标队列 my $fifo = “/var/log/local6.err”; # 首先检测 fifo 的有效性 local $SIG{ALRM} = sub { die "alarm\n" }; eval { alarm 4; open(PIPE, $fifo) or die print “Error: $fifo can not be opened.\n”; alarm 0; }; if ($@ =~ /alarm/) { close PIPE; exit 0; } # 读取 fifo my $allinfo = ""; while (1) { my $line; eval { alarm 2; $line = <PIPE>; alarm 0; }; if ($@ =~ /alarm/) { close PIPE; # 如果读到系统错误日志,邮件通知系统管理员 if ($allinfo) { my $command = “echo \“$allinfo\” | mail -s \”$fifo\” root”; my $rc = system($command); if ($rc) { print “Notification to root failed.\n”; } } exit 0; } $allinfo .= $line; } close PIPE; |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | # mail mailx version nail 11.25 7/29/05. Type ? for help. "/var/mail/root": 1 message 1 new >N 1 root@p6hv8n02.clus Tue Apr 14 03:19 21/808 /var/log/monitor.warn ? Message 1: From root@p6hv8n02.clusters.com Tue Apr 14 03:19:37 2009 X-Original-To: root Delivered-To: root@p6hv8n02.clusters.com Date: Tue, 14 Apr 2009 03:19:37 +0000 To: root@p6hv8n02.clusters.com Subject: /var/log/monitor.warn User-Agent: nail 11.25 7/29/05 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit From: root@p6hv8n02.clusters.com (root) Apr 14 03:19:26 p6hv8n02 root: This is a local6.err test message1. Apr 14 03:19:28 p6hv8n02 root: This is a local6.err test message2. Apr 14 03:19:30 p6hv8n02 root: This is a local6.err test message3. |
1 2 3 4 5 6 7 8 9 10 11 12 | # cat /etc/apparmor.d/sbin.syslog-ng #include <tunables/global> /sbin/syslog-ng { #include <abstractions/base> . . . /var/run/syslog-ng.pid w, /var/log/local6.err wr, } # /etc/init.d/boot.apparmor restart |
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |