亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費(fèi)注冊(cè) 查看新帖 |

Chinaunix

  平臺(tái) 論壇 博客 文庫
最近訪問板塊 發(fā)新帖
查看: 1660 | 回復(fù): 0
打印 上一主題 下一主題

check md5 v1.0 [復(fù)制鏈接]

論壇徽章:
0
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報(bào)告]
發(fā)表于 2010-08-16 15:04 |只看該作者 |倒序?yàn)g覽
本帖最后由 reistlin 于 2010-08-16 15:08 編輯

作者: reistlin
來源: http://www.reistlin.com/blog/32
更新時(shí)間: 2010.08
版權(quán)聲明: 原創(chuàng)文章.轉(zhuǎn)載請(qǐng)保留作者信息和原文完整.謝絕任何方式的摘要
  1. #!/usr/bin/perl -w

  2. # Name: check md5 v1.0
  3. # Author: reistlin
  4. # Website: www.reistlin.com
  5. # Hotfix: bigyong
  6. # Website: www.bigyong.com
  7. # Date: 2010.08.02

  8. use strict;
  9. use Data::Dumper;
  10. use Digest::MD5 qw(md5 md5_hex md5_base64);


  11. # Debug Switch
  12. my $debug = 0;

  13. # Start Time
  14. my $time_1 = time();
  15. # Clear
  16. system "clear";


  17. # Defined Original Hash File
  18. my $original_file = "./check_md5.log";
  19. my %original_hash;

  20. # Defined CheckList Directory
  21. my $checklist_dir = "/home/reistlin";

  22. # Defined Exclude Directory
  23. my $exclude_tag = 0;
  24. my @exclude_dir = ("/home/reistlin/exclude1", "/home/reistlin/exclude2");
  25. my $exclude_key = join("|", @exclude_dir);

  26. # Defined Result
  27. my @md5_ok;
  28. my @md5_no;
  29. my @md5_bad;


  30. # Check Hash File
  31. if ( ! -e $original_file ) {
  32.         print "[Error] Can not open MD5 logfile [$original_file] \n";
  33.         print "[Error] Please run the \[create_md5.pl\] to create original MD5 logfile \n";
  34.         exit;
  35. } else {
  36.         # check file stat
  37.         &filestat($original_file);

  38.         # load hash file
  39.         open(FILE, $original_file);

  40.         while (<FILE>) {
  41.                 my $line = $_;
  42.                 if ( $line =~ m/(.+)\s+(.+?)\s*$/ ) {
  43.                         $original_hash{$2} = $1;
  44.                 }
  45.         }
  46.         close(FILE);
  47. }


  48. # List file Check MD5
  49. sub checkmd5 {
  50.         my $path = shift;
  51.         # clean path end "/"
  52.         $path =~ s/\/+$//;

  53.         opendir(DIR, $path) or die "[Error] Can not check directory [$path] \n";
  54.         my @list = readdir(DIR);
  55.         closedir(DIR);

  56.         foreach my $tmp (@list) {
  57.                 # exclude "." or ".."
  58.                 next if ( $tmp =~ m/^\.+$/ );
  59.                 # full path
  60.                 my $path_sub = $path . "/" . $tmp;
  61.                 # exclude directory
  62.                 next if ( ( $path_sub =~ /$exclude_key/ ) && ( $exclude_tag == 1 ) );
  63.                 # subdirectory recursive
  64.                 if ( -d $path_sub ) {
  65.                         &checkmd5($path_sub);
  66.                 } else {
  67.                         # check key
  68.                         if ( exists $original_hash{$path_sub} ) {
  69.                                 # check md5
  70.                                 if ( $original_hash{$path_sub} eq &md5sum($path_sub) ) {
  71.                                         push @md5_ok, $path_sub;
  72.                                 } else {
  73.                                         push @md5_bad, $path_sub;
  74.                                 }
  75.                         } else {
  76.                                 push @md5_no, $path_sub;
  77.                         }
  78.                 }
  79.         }
  80. }


  81. # MD5 Check Mode
  82. sub md5sum {
  83.         my $file = shift;
  84.         open(FILE, $file) or die "[Error] Can not check file [$file] \n";
  85.         binmode(FILE);

  86.         my $md5 = Digest::MD5->new();
  87.         $md5->addfile(*FILE);

  88.         close(FILE);

  89.         $md5->hexdigest;
  90. }


  91. # File Stat Mode
  92. sub filestat {
  93.         my $file = shift;
  94.         my @file_stat = stat($file);
  95.         my $mtime = localtime $file_stat[9];
  96.         my $ctime = localtime $file_stat[10];

  97.         print "\n";
  98.         print "[$file] Modify: $mtime \n";
  99.         print "[$file] Change: $ctime \n";
  100.         print "[$file] UID: $file_stat[4] \n";
  101.         print "[$file] GID: $file_stat[5] \n";
  102.         print "[$file] Size: $file_stat[7] bytes \n";
  103.         print "\n";
  104. }


  105. # Print Array Mode
  106. sub print_array {
  107.         my @array = @_;
  108.         foreach my $tmp (@array) {
  109.                 print "$tmp \n";
  110.         }
  111. }


  112. # Main Program
  113. &checkmd5($checklist_dir);


  114. # Print Result Mode
  115. my $scalar_ok = scalar(@md5_ok);
  116. my $scalar_no = scalar(@md5_no);
  117. my $scalar_bad = scalar(@md5_bad);

  118. print "[OK MD5] $scalar_ok Files:\n";
  119. &print_array(@md5_ok);
  120. print "\n";

  121. print "[NO MD5] $scalar_no Files:\n";
  122. &print_array(@md5_no);
  123. print "\n";

  124. print "[BAD MD5] $scalar_bad Files:\n";
  125. &print_array(@md5_bad);
  126. print "\n";


  127. # End Time
  128. my $time_2 = time();
  129. my $time = $time_2 - $time_1;

  130. # Script Runtime
  131. print "Runtime \[$time\] Seconds ... \n";
  132. print "End! Good Luck! :-) \n";
  133. print "\n";
復(fù)制代碼
您需要登錄后才可以回帖 登錄 | 注冊(cè)

本版積分規(guī)則 發(fā)表回復(fù)

  

北京盛拓優(yōu)訊信息技術(shù)有限公司. 版權(quán)所有 京ICP備16024965號(hào)-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號(hào):11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報(bào)專區(qū)
中國互聯(lián)網(wǎng)協(xié)會(huì)會(huì)員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關(guān)心和支持過ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請(qǐng)注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP