LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-29-2001, 03:42 PM   #1
killjoy
Member
 
Registered: Mar 2001
Location: Atlanta,GA
Distribution: Red Hat, Mandrake
Posts: 66

Rep: Reputation: 15

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";
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
please help .perl Script/ apenguinlinux Programming 4 08-10-2005 09:04 PM
perl script Arnaud_B Linux - Newbie 13 07-31-2005 02:27 PM
Converting a Windows Perl script to a Linux Perl script. rubbercash Programming 2 07-19-2004 10:22 AM
how to find the pid of a perl script from shell script toovato Linux - General 1 12-19-2003 06:25 PM
Including methods from a perl script into another perl script gene_gEnie Programming 3 01-31-2002 05:03 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:49 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration