史蒂夫和斯凯 发表于 2018-8-31 11:31:25

利用Perl检测系统中与系统用户相关的进程

  # cat check.pl
  #!/bin/perl
  unless($#ARGV == 0){die "Usage: $0 : $!";}
  open(PASSWD,"/etc/passwd")or die "cant open:$!";
  $username=shift(@ARGV);
  print "$username.\n";(---改行可以不要,当时是为了测试用的!)
  while($pwline=){
  if($pwline =~/$username:/){print "$username is a system user here\n";last;}
  else {die "$username is not a system user here\n";}
  }
  close PASSWD;
  open(LOGGEDON,"who|")or die "cant open:$!";
  while($logged=){
  if($logged =~ /$username/){$logged_on=1;last;}
  }
  close LOGGEDON;
  die "$username is not logged on.\n" if !$logged_on;
  print "$username is logged on and running these processed.\n";
  open(PROC,"ps aux|") or die "cant open: $!";
  while($line=){
  print "$line" if("$line" =~/^$username/);
  }
  close PROC;
  print "*"x 10,"\n";
  print "so long.\n";
  #

页: [1]
查看完整版本: 利用Perl检测系统中与系统用户相关的进程