原贴:http://www.dbanotes.net/opensource/logwatch_linux_log.html
如果要想迅速的得到 Linux 环境中的日志报告信息, Logwatch 是一个很好的工具.
一般的 Linux 系统中可能都默认安装了这个工具.几乎不需要额外的配置就可以简单的用起来.
# logwatch --print
这条命令将会把昨天的日志信息简要的打印出来. 比如用户登录失败信息、SSH 登录信息、磁盘空间使用等.
单独查看某个服务,比如 SSH 登录信息:
# logwatch --service sshd --print
这条命令可以查看使用说明:
# logwatch --help
最新版本的 LogWatch 默认有 70 多种 Log 的配置信息. 如果要对自己的特殊 Log 做监控, 定制也是比较容易的。简单记录一下:
基本的做法:
1) 创建一个日志文件组。指定自己的 Log 文件,可以是一个,可以是多个;
2) 创建一个新的服务。指明这个服务的名字, 指明 Log 文件来源(来自上一步的定义);
3) 创建一个过滤脚本;
整个原理就是,LogWatch 首先要知道针对哪一个服务, 从这个服务中得到需要处理的 Log 文件信息, 然后这个文件送给过滤脚本处理, 之后把处理后格式化的信息展现出来;
出于时间关系,例子就不给了。
安全:
LogWatch 旧版本 2.11 有个著名的漏洞:临时目录建立处理中存在竞争条件漏洞。这里有溢出代码:Root Compromise through LogWatch
其他: LogWatch 报告的是 Log 信息的历史数据,如果要实时监控 Log,可以考虑用 Swatch.
<script type="text/javascript">
</script> <script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript"> </script> <script language="JavaScript1.1" src="http://pagead2.googlesyndication.com/cpa/ads?client=ca-pub-2198040673582211&cpa_choice=CAAQhaT2_gEaCI52gVKP95-sKLGsuIEBMAA&oe=utf-8&dt=1189773799250&lmt=1189604923&format=ref_text&output=textlink&correlator=1189773799234&url=http%3A%2F%2Fwww.dbanotes.net%2Fopensource%2Flogwatch_linux_log.html®ion=_google_cpa_region_&ref=http%3A%2F%2Fwww.dbanotes.net%2Fopensource%2Fext3_superblock_recovery.html&cc=100&ga_vid=133643345.1189773799&ga_sid=1189773799&ga_hid=52942695&flash=9&u_h=1024&u_w=1280&u_ah=874&u_aw=1280&u_cd=32&u_tz=480&u_his=3&u_java=true" type="text/javascript"></script> Get Firefox with Google Toolbar for better browsing
<script type="text/javascript">
</script> <script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript"> </script> <script language="JavaScript1.1" src="http://pagead2.googlesyndication.com/cpa/ads?client=ca-pub-2198040673582211&cpa_choice=CAAQidTQgAIaCEapPfRcsfp6KN2uuIEBMAA&oe=utf-8&dt=1189773799421&lmt=1189604923&prev_fmts=ref_text&format=ref_text&output=textlink&correlator=1189773799234&url=http%3A%2F%2Fwww.dbanotes.net%2Fopensource%2Flogwatch_linux_log.html®ion=_google_cpa_region_&ref=http%3A%2F%2Fwww.dbanotes.net%2Fopensource%2Fext3_superblock_recovery.html&cc=100&ga_vid=133643345.1189773799&ga_sid=1189773799&ga_hid=52942695&flash=9&u_h=1024&u_w=1280&u_ah=874&u_aw=1280&u_cd=32&u_tz=480&u_his=3&u_java=true" type="text/javascript"></script> Generate revenue from your website. Google AdSense.