I'm writing a Perl script to use on our network to reset users accounts. I haven't done much with Perl previously and I want to have some confidence it won't screw up my network too much, SOOO...Here's the situation: I have 100+ users on a RH6.2 network running NIS and NFS. These people are not compu-savvy and have a habit of "playing" with their accounts until it's easier to make a new one than to fix the old one. The applications they use are all network or web-based apps, so there's no data on the local machine. This script is supposed to dump all their settings and return their account to a default state. It works fine on my workstation, but earlier versions crashed NFS-I fixed that, but was wondering if anyone out there would look this over and post suggestions for improvement or fix problems. (whew!)
Anyway, here's the script:
#!/usr/bin/perl
#### This script falls under GNU License
#### This is a perl script to reset the user's account to a default status in
#### RedHat 6.2 and will require rsync.
my $Command0 = "";
my $Command1 = "";
my $Command2 = "";
my $Command3 = "";
my $Command4 = "";
my $Command5 = "";
my $Command6 = "";
$Command0 = "/etc/rc.d/init.d/nfs stop";
$Command1 = "/etc/rc.d/init.d/nfslock stop";
print "Stopping NFS daemon.\n";
system "$Command0";
system "$Command1";
open(FILE,"</etc/passwd") or die "Can't find the file: $!" ;
while(my $txt=<FILE>)
{
my @array=split /:/,$txt;
### array[3] is the GID, array[2] is the UID--use whichever is needed here
if($array[3]==534)
{
print "Found user: ";
print $array[0]. ", updating...\n";
#### WARNING: this will delete EVERYTHING in the users HOME dir
$Command2 = "rm -rf $array[5]/*";
print "$Command2\n";
system "$Command2";
$Command2 = "rm -rf $array[5]/.*"
print "$Command2\n"
system "$Command2\n"
#### This returns the account to the default settings
$Command3 = "rsync -r /etc/skel.kfscsr/ $array[5]";
print "$Command3\n";
system "$Command3";
#### This returns ownership of the dir to the user
$Command4 = "chown -R $array[0]:$array[0] $array[5]";
print "$Command4\n";
system "$Command4";
print "done...continuing.\n";
}
else
{
print "User ID does not match, NEXT...\n";
}
}
$Command5 = "/etc/rc.d/init.d/nfs start";
$Command6 = "/etc/rc.d/init.d/nfslock start";
print "All selected users updated,\n";
print "Restarting NFS,\n";
system "$Command5";
system "$Command6";
print "exiting.\n";
|