D
dale
Here's what I'm trying to do in this block of code - I'm trying to get
the UIDs from /etc/passwd and present them to the user. Then, the
user can pick a UID not in the list. If the user picks a UID in the
list, user should have his hand slapped and be prompted to enter a new
value.
The "Get UID from user" and "Check to make sure it's a new UID" parts
are what I am having trouble with.
Here is the code:
############################################## GET UID #########
#
### Get /etc/passwd names and UIDs
my $toBe = "/etc/passwd";
my $copy = "/root/bin/temp";
copy($toBe, $copy) or die "\n Cannot open file \n";
`awk -F : '{print \$1"," \$3}' /root/bin/temp > tempUID`;
`rm -f /root/bin/temp`;
### Read login names and UIDs into hash
my $tempUID = "/root/bin/tempUID";
open(FILE,"<$tempUID") || die "\nCan't read: $tempUID$!\n";
my $uid;
my $login;
while(<FILE>){
($login,$uid)=split(/,/,$_);
chomp $uid;
$hashUID->{$uid} = $login;}
### Print UIDs
$counter = 0; # reset counter
while (($uid, $login) = each(%$hashUID))
{
if ( ($uid >500)&&($uid < 5000) ){
print "\n\t$uid \t$login";}
}
### Get UID from user
sub get_UID{
print "\n\n These are the non-system logins on this system.
\n Please input a new UID to start your users with: ";
$uidInput=<>;
chomp $uidInput;}
get_UID();
### Check to make sure it's a new UID
foreach (keys (%$hashUID)) {
print "\nchecking UID"; ##for debugging
if ($uidInput == $uid) {
print "\n That UID exists already. Try another: ";
goto &get_UID;}
}
#
################################################################
the UIDs from /etc/passwd and present them to the user. Then, the
user can pick a UID not in the list. If the user picks a UID in the
list, user should have his hand slapped and be prompted to enter a new
value.
The "Get UID from user" and "Check to make sure it's a new UID" parts
are what I am having trouble with.
Here is the code:
############################################## GET UID #########
#
### Get /etc/passwd names and UIDs
my $toBe = "/etc/passwd";
my $copy = "/root/bin/temp";
copy($toBe, $copy) or die "\n Cannot open file \n";
`awk -F : '{print \$1"," \$3}' /root/bin/temp > tempUID`;
`rm -f /root/bin/temp`;
### Read login names and UIDs into hash
my $tempUID = "/root/bin/tempUID";
open(FILE,"<$tempUID") || die "\nCan't read: $tempUID$!\n";
my $uid;
my $login;
while(<FILE>){
($login,$uid)=split(/,/,$_);
chomp $uid;
$hashUID->{$uid} = $login;}
### Print UIDs
$counter = 0; # reset counter
while (($uid, $login) = each(%$hashUID))
{
if ( ($uid >500)&&($uid < 5000) ){
print "\n\t$uid \t$login";}
}
### Get UID from user
sub get_UID{
print "\n\n These are the non-system logins on this system.
\n Please input a new UID to start your users with: ";
$uidInput=<>;
chomp $uidInput;}
get_UID();
### Check to make sure it's a new UID
foreach (keys (%$hashUID)) {
print "\nchecking UID"; ##for debugging
if ($uidInput == $uid) {
print "\n That UID exists already. Try another: ";
goto &get_UID;}
}
#
################################################################