电脑故障

位置:IT落伍者 >> 电脑故障 >> 浏览文章

ssh单用户登录写法


发布日期:2022/2/21
 

#!/usr/bin/perl w
use strict;
sub main
{
my @lines = `ps教程 eo userpidetimecmd | grep sshd`;
my $users;
for my $line (@lines) {
if(my ($user $pid $etime $cmd) = $line =~ /^([^s]+)s+(d+)s+([^s]+)s+(sshd:+)$/) {
next if($user eq ‘root’);
my $proc = {‘pid’ $pid ‘etime’ $etime ‘cmd’ $cmd};
push @{$users>{$user}} $proc;
}
}
for my $key(keys(%$users)) {
my @sshs = sort {
my ($lb $la) = (length($b>{‘etime’}) length($a>{‘etime’}));
if($lb == $la) {
$b>{‘etime’} cmp $a>{‘etime’};
} else {
$lb <=> $la;
}
} @{$users>{$key}};
for ( ) { shift @sshs; };
for my $ssh (@sshs) {
kill $ssh>{‘pid’};
}
}
}
while() {
main;
sleep ;
}

上一篇:SSH集成开发面试问题

下一篇:系统找不到指定的文件 No installed service named Apach