- 论坛徽章:
- 0
|
回复 #1 gaochong 的帖子
以上代码有点儿问题,一来没有close DIG,二来没有检查 $? 的值。
修改后的代码如下:
#!/usr/bin/perl -w
use strict;
use POSIX qw/strftime/;
local $"="\t";
my $dig="/usr/sbin/dig";
my $ns="ip_ns";
my $log="/dig.log";
my $date=strftime ("%Y%m%d",localtime);
my @list;
my @domains=qw/
www.google.com
www.sina.com.cn
/;
foreach my $domain(@domains) {
push @list,&dig_time($domain);
}
open FILE,">> $log" or
die "$!";
print FILE "$date\t@list\n";
close FILE;
sub dig_time {
my $time;
my ($dom)=@_;
open (DIG,"$dig $dom \@$ns +trace|") or
die "Unable to dig:$!\n";
while (<DIG>;) {
if (/in\s(\d+)\sms$/) {
$time+=$1;
}
}
close DIG; #修正
return $? ? "NULL" : $time; |
[ 本帖最后由 gaochong 于 2009-6-24 13:08 编辑 ] |
|