熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> Java編程 >> Java高級技術 >> 正文

ssh單用戶登錄寫法

2022-06-13   來源: Java高級技術 

#!/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 ;
}



From:http://tw.wingwit.com/Article/program/Java/gj/201404/30500.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.