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