Skip to content

Commit bbf39e7

Browse files
committed
a tool script for kicked out users quickly.
1 parent fb26c09 commit bbf39e7

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

kickOut.pl

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/bin/env perl
2+
3+
# kickOut.pl -- a tool script for kicked out the users. {{{1
4+
# use the cmd "w" and "who am i" get user info.
5+
# use the cmd "pkill -KILL -t user" kicked out user.
6+
#
7+
# Author: soarpenguin <[email protected]>
8+
# First release Dec.8 2013
9+
# 1}}}
10+
11+
use Term::ANSIColor;
12+
13+
my $DEBUG = 0;
14+
if ($DEBUG) {
15+
eval q{
16+
use Smart::Comments;
17+
};
18+
die $@ if $@;
19+
}
20+
21+
# get the current user.
22+
my $me = `who am i`;
23+
(undef, $me) = split(/\s+/, $me);
24+
### $me
25+
26+
# get all users current logged.
27+
my @other=`w`;
28+
my $user;
29+
30+
print color("blue"), "Kicked out all users?\n", color("reset");
31+
print "Input(yes/no):";
32+
my $answer = <STDIN>;
33+
if ($answer !~ /y|Y|YES|yes/) {
34+
exit 0;
35+
}
36+
37+
for(my $i = 2; $i < @other; $i++) {
38+
(undef, $user) = split(/\s+/, $other[$i]);
39+
if ($user !~ /pts/) {
40+
### $user
41+
next;
42+
} elsif ($user =~ /$me/) {
43+
### $user
44+
next;
45+
} else {
46+
### $user
47+
`pkill -KILL -t $user`;
48+
if ($? != 0) {
49+
print "Kill the $user failed.\n";
50+
}
51+
}
52+
}
53+

0 commit comments

Comments
 (0)