#25 Disabling a User

One of your students has violated the no hacking policy repeatedly. So you're going to give him a time-out for a few weeks and turn off his account.

Note:

This script is system dependent. Don't run it on your system until you've inspected it and know it fits your operation.

The Code

 1 #!/usr/bin/perl 2 use strict; 3 use warnings; 4 5 if ($#ARGV != 0) { 6 print STDERR "Usage is $0 <account>\n"; 7 } 8 9 my $user = $ARGV[0]; 10 11 # Get login information 12 my $uid = getpwnam($user); 13 if (not defined($uid)) { 14 print "$user does not exist.\n"; 15 exit (8); 16 } 17 18 system("passwd -l $user"); 19 my @who = 'who'; 20 @who = grep /^$user\s/, @who; 21 foreach my $cur_who (@who) { 22 my @words = split /\s+/, $cur_who; 23 ...

Get Wicked Cool Perl Scripts now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.