-
Notifications
You must be signed in to change notification settings - Fork 1
/
dis_user.pl
75 lines (56 loc) · 1.43 KB
/
dis_user.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/perl
=pod
=head1 NAME
dis_user.pl - Disable a user
=head1 SYNOPSIS
dis_user.pl <user>
=head1 DESCRIPTION
The I<dis_user.pl> command disables a user account. If he is logged in, he told
that the account is being disabled and given few seconds to get out of town.
Then all his processes are killed and account disabled.
=head1 AUTHOR
Steve Oualline, E<lt>[email protected]<gt>.
=head1 COPYRIGHT
Copyright 2005 Steve Oualline.
This program is distributed under the GPL.
=cut
use strict;
use warnings;
if ($#ARGV != 0) {
print STDERR "Usage is $0 <account>\n";
}
my $user = $ARGV[0];
# Get login information
my $uid = getpwnam($user);
if (not defined($uid)) {
print "$user does not exist.\n";
exit (8);
}
system("passwd -l $user");
my @who = `who`;
@who = grep /^$user\s/,@who;
foreach my $cur_who (@who) {
my @words = split /\s+/, $cur_who;
my $tty = $words[1];
if (not open(YELL, ">>/dev/$tty")) {
next;
}
print YELL <<EOF ;
*********************************************************
URGENT NOTICE FROM THE SYSTEM ADMINISTRATOR
This account is being suspended. You are going to be
logged out in 10 seconds. Please exit immediately.
*********************************************************
EOF
close YELL;
}
sleep(10);
my @procs = `ps -u $user`;
shift @procs;
foreach my $cur_proc (@procs) {
$cur_proc =~ /(\d+)/;
if (defined($1)) {
print "Killing $1\n";
kill 9, $1;
}
}