文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>一个根据校验文件检查文件是否正确并记录日志的程序

一个根据校验文件检查文件是否正确并记录日志的程序

时间:2008-02-29  来源:starB6

#!/usr/bin/perl -w
use strict;
use IO::Socket;
my $chkname ;
my $chkline ;
my $chksize ;
system(`rm -f chekerr.log`); open SOU," < chk.log";  #打开文件。
open LOGFILE," >> /odfs01/oddev3/proc_xd/myl/perl/data/chekerr.log";#打开记录处理日志的文件
my $a = localtime(time);
print  LOGFILE "the start time is : $a\n";#得到系统时间
foreach(<SOU>)
{
 open FILE ,"< $_"; 
 my $file = $_;
 chomp($file);
 my @totalsize=stat(FILE);
 my $size=$totalsize[7];
 chomp($size);  # 得到文件大小
 my   $len =` head -n 1 $file |awk '{print length(\$0)}'  `;
  my $length =  $len + 1;  
  my $line = $size / $length;   #  得到文件长度
  # 读校验文件,获得在生产机上的该文件大小与长度。
  open CHKFILE ,"$file.chk" ;  #打开校验文件句柄
  foreach(<CHKFILE>)
  {
   my $chkfile=$_;
   #  print "chkfile is : $chkfile \n";
   my @chkarray=split(/,/,$chkfile);
   my $chkname = $chkarray[0];
   my $chkline = $chkarray[1];
   my $chksize = $chkarray[2];  # 得到文件对应的校验文件的大小,行数等。
   
     if ($line==$chkline && $size==$chksize)
     {    
     }
     elsif($line!=$chkline)
     {
    print LOGFILE "ERROR !! , file $chkname 's  line is $line ,line in $chkname.chk is $chkline \n";
   # print "ERROR!!  the error file is : $chkname,there are some wrong here ,please check the data!\n";
     }
     elsif($size!=$chksize)
     {
   print LOGFILE  "ERROR !! , file $chkname 's  size is $size ,size in $chkname.chk is $chkname \n";
     } 
  }
}
my $b = localtime(time);
print  LOGFILE "the end time is : $b\n"; # 得到结束时间
 close(LOGFILE);
 close(CHKFILE);
相关阅读 更多 +
排行榜 更多 +
坦克战争世界

坦克战争世界

模拟经营 下载
丛林反击战

丛林反击战

飞行射击 下载
几何飞行安卓版

几何飞行安卓版

飞行射击 下载