通过DELL服务器的序列号,可以在其网站查询到有关该序列号对应的服务器信息,如果服务器过多,逐一查询的工作量比较大,可以通过命令行方式来查询

1、单一序列号查询:

  1. #!/usr/bin/perl -w  
  2. use utf8;  
  3. binmode( STDOUT, ':encoding(utf8)' );  
  4. use LWP::Simple;  
  5.  
  6. if ($#ARGV+1 != 1 ) {  
  7.     print "\nUsage: $0 <sn>\n";  
  8.     exit;  
  9. }  
  10.  
  11. #my $sn = shift;  
  12. my $sn = $ARGV[0];  
  13. print "$sn\n";  
  14. my $url = "http://supportapj.dell.com/support/topics/topic.aspx/ap/shared/support/my_systems_info/zh/cn/details?c=cn&l=zh&s=gen&~ck=anavml&servicetag=$sn";  
  15. my $content = get $url;  
  16.  
  17. my %h = $content =~ m{(系统类型:).*"top">(.*?)<.*(出厂日期:).*"top">(.*?)<.*(国家和地区:).*?"top">(.*?)<};  
  18.  
  19. print $_$h{$_}, "\n" for keys %h; 

输出:

  1. [root@flyinweb dell]# ./getdellinfobysn.pl  
  2.  
  3. Usage: ./simple.pl <sn>  
  4. [root@flyinweb dell]# ./getdellinfobysn.pl 1rcgw1x   
  5. 1rcgw1x  
  6. 系统类型:PowerEdge 1850  
  7. 国家和地区:China  
  8. 出厂日期:2005/12/31 

2、批量查询

可以将序列号存储在文件中,通过脚本读取每一行,然后调用上述脚本通过以下脚本来进行:

  1. #!/usr/bin/perl -w  
  2. # getinfobysn.pl  
  3. use utf8;  
  4. binmode( STDOUT, ':encoding(utf8)' );  
  5. use LWP::Simple;  
  6.  
  7. open(INFILE1, "sn.txt");  
  8. #open(OUTFILE, "+>result.txt")|| die "Cannot open the newfile: $!\n";  
  9.  
  10. foreach $x (<INFILE1>){  
  11.     chomp $x;  
  12.     print "$x\n";  
  13.     my $url ="http://supportapj.dell.com/support/topics/topic.aspx/ap/shared/support/my_systems_info/zh/cn/details?c=cn&l=zh&s=gen&~ck=anavml&servicetag=$x";  
  14.     my $content = get $url;  
  15.  
  16.     my %h = $content =~ m{(系统类型:).*"top">(.*?)<.*(出厂日期:).*"top">(.*?)<.*(国家和地区:).*?"top">(.*?)<};  
  17.     print $_$h{$_}, "\n" for keys %h;  
  18.     print "\n";  
  19. }  
  20.  
  21. #close  OUTFILE;  
  22. close  INFILE1;  
  23. exit

输出:

  1. # 输出  
  2. # [root@flyinweb dell]# ./getinfobysn.pl        
  3. # 41G833X  
  4. # 系统类型:PowerEdge R410  
  5. # 国家和地区:China  
  6. # 出厂日期:2011/3/16  
  7.  
  8. # HKW5Y2X  
  9. # 系统类型:PowerEdge R410  
  10. # 国家和地区:China  
  11. # 出厂日期:2010/8/18 

本日志由 flyinweb 于 2011-11-11 17:18:10 发表,目前已经被浏览 407 次,评论 0 次;

作者添加了以下标签: DELL Server Info

引用通告:http://www.517sou.net/Article/717/Trackback.ashx

评论订阅:http://www.517sou.net/Article/717/Feeds.ashx

评论列表

    暂时没有评论
(必填)
(必填,不会被公开)