日志文件的快速删除

我们知道,如果mysql中打开full query log或者slow query log的话,2个log文件大小会快速的增加,一天时间都能上G。而且mysql没有选项来控制log文件的大小,比如每10M就新建一个文件等等。 以前的做法是,stop mysql, delete log file,start mysql,笨吧。mysqlperformanceblog的这篇文章提供一个好办法:将需要删除的日志改名,然后运行FLUSH LOGS即可重新生成新的日志文件,简单吧? 另,linux下,echo > log 也可以完成这个任务。 原文:http://www.mysqlperformanceblog.com/2007/12/09/be-careful-rotating-mysql-logs/

2007年12月17日 · 1 分钟 · zgia

messages日志文件中IP获取小程序

日志内容: …… authentication failure; logname= uid=0 euid=0 tty=NODEVssh ruser= rhost=61.146.178.13 authentication failure; logname= uid=0 euid=0 tty=NODEVssh ruser= rhost=bin86.ee.ccu.edu.tw authentication failure; logname= uid=0 euid=0 tty=NODEVssh ruser= rhost=137.65.134.61.net.jq.gs.dynamic.163data.com.cn …… #!/usr/bin/perl use strict; # Open log file open(XXX, "/path/to/logfile") || die "Error Reading File : $!"; my @urls = <xxx>; close(XXX); my $i = 0; my @ips = (); for my $ip (@urls) { #if ($ip =~ /rhost=((d{1,3}.d{1,3}.d{1,3}.d{1,3})?.*) /isg) { if ($ip =~ /rhost=(.*) /isg) { $i ++; unless (is_in_array($1, @ips)) { push @ips, $1; } } } print "All attack count : $in"; print "Use $#ips IP(s)n"; print "The ips are : @ipsn"; sub is_in_array { my $ip = shift(); my $s = shift(); my @ips = @$s; my $in = 0; for (@ips) { if ($_ eq $ip) { $in = 1; last; } } return $in; }

2007年9月28日 · 1 分钟 · zgia