mailfiter 过滤ip
#--------ip filter------------ if(/^Received: from (.*) by (.*)/) { FROMIP=$MATCH1 if($FROMIP ne "") { if (lookup($FROMIP, ".blockip")) { echo "[block ip]::$FROMIP::F:$SENDER,T:$EXT@$HOST,drop letter" to /dev/null exit } } }
log4perl使用-按照日期划分log文件
http://search.cpan.org/~mschilli/Log-Log4perl/
首先 安装log4perl
perl -MCPAN -e "install Log::Log4perl"
windows中的ActivePerl 可以用ppm来安装
下面是例子
use strict; use warnings; use Cwd; my $curdir = getcwd; use Log::Log4perl; #按照日期来分割log文件 use POSIX qw(strftime); my $log_file = "subject".strftime("%Y-%m-%d", localtime(time)).".log"; my $conf = qq{ log4perl.category.Foo.Bar = INFO,Logfile log4perl.appender.Logfile = Log::Log4perl::Appender::File log4perl.appender.Logfile.filename = $curdir/$log_file log4perl.appender.Logfile.layout = Log::Log4perl::Layout::PatternLayout log4perl.appender.Logfile.layout.ConversionPattern = %d{20y-M-d H:m:s:S} %F %L - %m%n }; #初始化 log4perl 配制文件 Log::Log4perl::init (\$conf); my $log = Log::Log4perl::get_logger("Foo::Bar"); $log->info("信息 ");
-------------
另外 $conf 配置也可以写在文件里面:
Log::Log4perl::init("log3perl.conf");
qmail .mailfilter 过滤中文标题垃圾邮件
if(/^Subject:.*/) { SUBJECT=$MATCH #提取出base64编码的邮件标题 #echo "[subject]::$SUBJECT" } if ($SUBJECT ne "") { #将标题转换为中文 #maildecod 请访问http://hello386.is-programmer.com/posts/25736.html NSUB=`/usr/local/sbin/maildecod $SUBJECT` #echo "[NSUB]::$NSUB" } if (lookup($NSUB, ".badsubject")) { echo "[bad_subject]::$SUBJECT::F:$SENDER,T:$EXT@$HOST,drop letter" to /dev/null exit }
将qmail邮件标题从base64转换为中文
#!/usr/bin/perl $sub=join(" ",@ARGV); if ($sub=~ /=\?\S+\?\l(\S)\?/) { if ($1 =~ /[Qq]/) { $sub=decode_qp($sub); } elsif ($1 =~ /[Bb]/) { $sub=decode_base64($sub); } } elsif ($sub=~ /=[a-fA-F0-9][a-fA-F0-9]/) { $sub=decode_qp($sub); } $subject.=$sub; $subject=~s/\'/\\\'/g; $subject=~s/\"/\\\"/g; print $subject; # for test #最好是将生成的subject.log copy一份,在这个基础上修改成为badsubject 主要是怕编码不对 #open(FILE,">> /tmp/subject.log"); #print FILE "$subject\n"; #close(FILE); sub decode_qp { my($string) = @_; @buffer=split(/\?/,$string); $string = $buffer[3] if ($buffer[3] ne ""); $string =~ s/=([\da-fA-F]{2})/pack("C", hex($1))/ge; $string =~ /\?=(.*)/; $string =~ tr/_/ /; $buffer[4]=~s/^=//; $buffer[0]=~s/=$//; $string="$buffer[0]$string$buffer[4]"; return($string); } sub decode_base64 { my($string) = @_; my($string2); @buffer=split(/\?/,$string); $string = $buffer[3] if ($buffer[3] ne ""); $string =~ s/=+$//; $string =~ tr|A-Za-z0-9+/| -_|; while($string =~ /(.{1,60})/gs) { my($string3) = chr(32+length($1)*3/4); $string2 .= unpack("u",$string3 . $1 ); } $buffer[4]=~s/^=//; $buffer[0]=~s/=$//; $string2="$buffer[0]$string2$buffer[4]"; return($string2); }
Perl命令行应用介绍[转]
作 者: Dave Cross 发 表:August 10, 2004 原 名: Perl Command-Line Options 原 文:http://www.perl.com/pub/a/2004/08/09/commandline.html 译 者: "Qiang":qiang
perl 判断文件是否存在并创建目录
use File::Path;
if(-e $x) { #abc.txt是否存在?
# 存在操作
} else {
printf "文件不存在。\n";
my $path='F:/01/012/013;
eval{mkpath($path,0,0755)};
if($@)
{
warn("Make path [$path] failed:\n$@");
}
}
Perl文件及目录操作
perl 修改文件
详细请google Tie::File 之
prel 操作注册表
perl 操作注册表函数 查看全文请猛击标题 *_*
PERL,执行ORACLE存储过程.
BEGIN
procName;
END;
");
多谢 beckheng 和 Justin
#一下是个例子
$dbname="XXTDB"; #数据库名称
$user="scott"; #用户名
$passwd="xxt"; #密码
$dbh="";
print "------------------------------------------\n";
print " by kuaidao \n";
print " e-mail: maxiaodou at 126.com \n";
print "------------------------------------------\n";
print "connect the db $dbname.....\n";
#连接数据库
$dbh = DBI->connect("dbi:Oracle:$dbname",$user,$passwd) or die "can't connect todatabase ". DBI-errstr;
#开始执行存储过程 REP_MAP
$dbh->do("
BEGIN
REP_MAP;
END;
");
$dbh->disconnect;
print " ok DB disconnect\n"