TStanley has asked for the wisdom of the Perl Monks concerning the following question:
Any suggestions would be helpful. Thanks.#!/usr/bin/perl -w use strict; my $PASSWD="/etc/passwd"; my $TMP="/tmp/passwd"; my %LAB=("telcom"=>143,"mgrst"=>138,"dcbst"=>146,"posst"=>152, "unity"=>1042,"cron.st"=>135,"admins"=>144,"amgst"=>138); my %EXCEPTIONS=("mgrst"=>0,"amgst"=>0,"dcbst"=>0,"posst"=>0); my %UIDS=(); my $server=`uname`; chomp($server); my $ext=substr($server,-3); my $key; #This code will have to be run on a server in each #of our stores. The last 3 characters in the server #name is the store number. The accounts listed in the #EXCEPTIONS have to have the store number appended to #it. foreach $key(keys %LAB){ if(exists $EXCEPTIONS{$key}){ my $newkey = $key.$ext; $UIDS{$newkey}=$LAB{$key}; }else{ $UIDS{$key}=$LAB{$key}; } } my $line; open(PWD,"$PASSWD")||die"Can't open $PASSWD: $!\n"; open(TMP,">$TMP")||die"Can't open $TMP: $!\n"; # Now here's where I am having trouble while(<PWD>){ my($name,$passwd,$uid,$gid,$gcos,$dir,$shell)=split /:/; foreach $key(keys %UIDS){ if($key eq $name){ $uid=$UIDS{$key}; $line=join ':',$name,$passwd,$uid,$gid,$gcos,$dir,$shell; print TMP $line; }else{ $line=join ':',$name,$passwd,$uid,$gid,$gcos,$dir,$shell; print TMP $line; }#end of if/else }#end of foreach }#end of while loop close PWD; close TMP;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Changing UIDs
by japhy (Canon) on Jul 10, 2001 at 23:42 UTC | |
|
Re: Changing UIDs
by tadman (Prior) on Jul 10, 2001 at 23:44 UTC |