查询用户信息

#!/usr/bin/perl -w
#Author:Hahazhu
#DATE:04/29/2008 11:02
#Role:view user information based on user name.
#USAGE:programe root
use strict;
my %search_name = ();
my @names;
my $i;
sub true_examples{
   print "USAGE:Program arg1\n";
   exit 1;
}
open(F,"/etc/passwd");
while(<F>){
  my ($name,$f1,$f2,$f3,$group,$home,$bash)=split(/\:/,$_);
  push( @names,$name);
  Create_Entries($name,$group,$home,$bash);
}
close F;
sub  Create_Entries{
     my($name,$group,$home,$bash)=@_;
     my $rl=[$group,$home,$bash];
     push (@{$search_name{$name}},$rl);
}
my $numargs=@ARGV;
if( $numargs != 1 ){
  &true_examples;
}
my $input_name = $ARGV[0];
print_search_name($input_name);
sub print_search_name{
  my ($input_name)=@_;
  foreach(@names){
     if($_ eq $input_name){
         print $input_name." information:\n";
         print "\tGroup:$search_name{$input_name}[0][0]\n";
         print "\tHome:$search_name{$input_name}[0][1]\n";
         print "\tBash:$search_name{$input_name}[0][2]";
         exit 0;
     }
     else
         { $i = 0 }
  }
  if ( $i == 0 ){
      print "\tERROR:ARG Error!\n";
      print "True ARG:\n";
      &print_arg;
      print "\n";
 }
}
sub print_arg{
  foreach(@names){
     print "\t".$_." ";
  }
}


本文转自hahazhu0634 51CTO博客,原文链接:http://blog.51cto.com/5ydycm/113491,如需转载请自行联系原作者
上一篇:惊!12306官网又现用户信息泄露?


下一篇:还有什么不能做?——细谈在C#中读写Excel系列文章之二