284354749 发表于 2018-8-31 10:55:39

利用perl检测系统中登陆用户相关的进程升级版

  #!/bin/perl
  open(FH,"user")or die "cant open file:$!";
  @lines=;
  chomp(@lines);
  close FH;
  #print "@lines\n";
  open(PASSWD,"/etc/passwd")or die "cant open:$!";
  foreach $username (@lines){
  #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";
  print "\n\n";
  }
  用户可以根据自己的需要再添加修改,比如,可以打印每个用户有几个进程正在运行,占用内存等等。

页: [1]
查看完整版本: 利用perl检测系统中登陆用户相关的进程升级版