加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

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

发布时间:2020-12-16 00:23:21 所属栏目:大数据 来源:网络整理
导读:#!/bin/perl open(FH,"user")or die "cant open file:$!"; @lines=FH; chomp(@lines); close FH; #print "@linesn"; open(PASSWD,"/etc/passwd")or die "cant open:$!"; foreach $username (@lines){ #print "$username.n"; while($pwline=PASSWD){ ??????

#!/bin/perl
open(FH,"user")or die "cant open file:$!";
@lines=<FH>;
chomp(@lines);
close FH;
#print "@linesn";
open(PASSWD,"/etc/passwd")or die "cant open:$!";
foreach $username (@lines){
#print "$username.n";
while($pwline=<PASSWD>){
??????? if($pwline =~/$username:/){print "$username is a system user heren";last;}
??????? else {die "$username is not a system user heren";}
}
close PASSWD;
open(LOGGEDON,"who|")or die "cant open:$!";
while($logged=<LOGGEDON>){
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=<PROC>){
print "$line" if("$line" =~/^$username/);
}
close PROC;
print "*"x 10,"n";
print "so long.n";
print "nn";
}
?

用户可以根据自己的需要再添加修改,比如,可以打印每个用户有几个进程正在运行,占用内存等等。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读