> I am having trouble with a portion of my custom add user script. I
> want to display the contents of /etc/groups (gid 500-531)
> numbered. I then want to input the number(s) of the groups I want to
> add the user to (input should be in csv). The catch is I don't want
> just any number to work - I want the user to be able to enter only
> the index # and a comma to delimit the entries.
'
> #sub GRPS {
>
> open (GROUP, "/etc/group");
A little paranoia goes a long way.
open (GROUP, "/etc/group")
or die ("can't open groups file: $!\n");
> while(<GROUP>) {
> chomp;
> @gid=split(/:/, $_);
> if ( $gid[2] > 499 && $gid[2] < 532 ) {
> push (@supgrp, "$gid[2],$gid[0]");
> }
> }
Good so far, but @supgrp is not as useful to you here as
a hash, so try:
my %supgrp;
while(<GROUP>) {
chomp;
@gid=split(/:/, $_);
if ( $gid[2] > 499 && $gid[2] < 532 ) {
$supgrp{$gid[2]} = $gid[0];
}
}
> printf "Listing available groups...\n\n";
> #do something @supgrp foreach $i (@supgrp) { ($gid,$name) = split(/,/,
Then, this will list the groups:
while (my ($gid, $name) = each %supgrp) {
print " $gid($name)\n";
}
And this will check the validity (more or less):
my $answer = ReadLine 0;
my @groups = split(/[\s,]+/, $answer);
my @bad = grep (!$supgrp{$_}, @groups);
if (@bad) {
warn "These groups were invalid: @bad\n";
} else {
# All good, go for it
}
Regards,
Jonathan
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]