What I posted earlier is pretty much it.  I basically want to change the
contents of a sudoers file for sudo.  I make almost all of the other
modifications in another script.  In the current script I want to find the
line that says  User_Alias    ACLPUSHER in the sudoers file and replace it
with itself and append = user1, user2, user3.  Of course users 1 through 3
are relative to the operator input. The line I am searching for is:
 
User_Alias    ACLPUSHER = test1, test2    #where test1 and test2 may vary
 
Okay I am pretty lame... I have a line in there using sed but I will change
it before I am done.  But basically I find the line User_Alias.*ACLPUSHER
and replace it.
 
 
 #!/usr/bin/perl 
while($ans !~ /^[a-z]+$/ || $ans !~ /^[a-z]+\,?[a-z]*$/) { 
   errmesg (); 
  $ans = <STDIN>; 
}; 

 `sed 's/^\(User_Alias.*ACLPUSHER\).*/\1 = '"$NAME"'/' s2`;

 sub errmesg { 
   print "\nType user name(s) and press enter:\n"; 
   print "note: if more than one separate using commas\n"; 
   print "example (single name): evan\n"; 
   print "example (multi name): debbie, clint, henry\n"; 
} 

Thanks again for your help,
Evan
 
P.S. Do you know if there is an ettiquette or rules page for this list?  I
have received mail from it for a long time but haven't posted much.  
 
 

-----Original Message-----
From: Paul Kraus [mailto:[EMAIL PROTECTED]]
Sent: Thursday, January 09, 2003 11:07 AM
To: Kehayias, Evan N Mr NISO/Lockheed Martin
Subject: RE: regular expressions


split takes an line and splits it by deliminator (perldoc -f split)
 
so if your input was
 
paul, david, kraus\n
 
then $names[0]="paul"
       $names[1]=" david" #notice the space.
       $names[2]=" kraus\n" #notice the new line. If you did not want the
new line make sure you chomp your input.
 
Why don't you post your script so far so we have a better idea of what your
trying to do.

-----Original Message-----
From: Kehayias, Evan N Mr NISO/Lockheed Martin
[mailto:[EMAIL PROTECTED]] 
Sent: Thursday, January 09, 2003 11:00 AM
To: [EMAIL PROTECTED]
Cc: 'Rob Dixon'; 'Paul Kraus'
Subject: RE: regular expressions



At this point could a user still input something like 7mary3.  Ideally a
user can enter a name or several separated by commas but *nothing* else.
Convention would be lowercase firstinitiallastname  It seems like Rob's is
really close but I don't understand all of the code.  I am a little shy with
arrays.  Is @names built as you go? And, is the input all one element? It
seems to me as if that is the case but not 100% sure.


-----Original Message----- 
From: Rob Dixon [ mailto:[EMAIL PROTECTED]
<mailto:[EMAIL PROTECTED]> ] 
Sent: Thursday, January 09, 2003 10:43 AM 
To: [EMAIL PROTECTED] 
Subject: Re: regular expressions 


Hi Paul 

See below. 

"Paul Kraus" <[EMAIL PROTECTED]> wrote in message 
021b01c2b7f3$490ed540$64fea8c0@pkrausxp">news:021b01c2b7f3$490ed540$64fea8c0@pkrausxp
<021b01c2b7f3$490ed540$64fea8c0@pkrausxp">news:021b01c2b7f3$490ed540$64fea8c0@pkrausxp> ... 
> Correct me if I am wrong but wouldn't 
> @names = sprit /,/,$ans; 

That's pretty much what I did, except that I added optional leading and 
trailing whitespace to the regex so that these would be trimmed from the 
names. I didn't actually do the job properly though, because whitespace at 
the start and end of $ans won't be removed, and input like '   Henrietta' 
will fail. Nearly right though! 

> Then you could perform your tests against the array elements. 
> if (/[A-Za-z]+/) 

Not really. That only checks to see if the name contains at least one alpha.

I did {/[^a-zA-Z]/ which checks for at least one non-alpha, when the loop 
continues and reports an error. Also you don't need the '+' modifier. 

> Assuming that the names would only contain those characters. 
> 
> or if (/\w+/) meaning all word characters. 

/\W/ would do in my code, but its unwholesome inclusion of the underscore in

a valid 'word' character makes it much less useful for non-programming apps.


> 
> Do the same thing. Splitting everything separated by a comma? 

Unsure what you mean here :-? I'll pretend you didn't say it. 

Cheers, 

Rob 

> 
> > -----Original Message----- 
> > From: Rob Dixon [ mailto:[EMAIL PROTECTED]
<mailto:[EMAIL PROTECTED]> ] 
> > Sent: Thursday, January 09, 2003 10:06 AM 
> > To: [EMAIL PROTECTED] 
> > Subject: Re: regular expressions 
> > 
> > 
> > Hello, erm, "Evan N Mr Niso/Lockheed Martin Kehayias" 
> > 
> > This should do what you want: 
> > 
> > 
> >     my @names; 
> >     do { 
> >         errmesg() if @names; 
> >         my $ans = <STDIN>; 
> >         @names = split /\s*,\s*/, $ans; 
> >     } while (grep {/[^a-zA-Z]/} @names); 
> > 
> > which splits on commas with any amount of preceding and 
> > trailing whitespace. Names have to be alphabetic. 
> > 
> > HTH, 
> > 
> > Rob 
> > 
> > 
> > "Evan N Mr Niso/Lockheed Martin Kehayias" 
> > <[EMAIL PROTECTED]> wrote in message 
> > 90AFE0B84E52EE46A8CD1DB0789C0A860ED043@DADC144">news:90AFE0B84E52EE46A8CD1DB0789C0A860ED043@DADC144
<90AFE0B84E52EE46A8CD1DB0789C0A860ED043@DADC144">news:90AFE0B84E52EE46A8CD1DB0789C0A860ED043@DADC144> ... 
> > > Greetings, 
> > > 
> > > I am attempting to limit entries a user could make when inputting 
> > > names 
> > into 
> > > one of my scripts.  I prompt the user to enter one or more 
> > names.  One 
> > name 
> > > is easy to isolate but when there are more I want to 
> > support commas. 
> > > At 
> > the 
> > > same time I don't want to accept anything other than names 
> > and commas. 
> > > I want to force the user to either enter names correctly or 
> > exit.  For 
> > > that matter it would be really cool if I could test the 
> > names against 
> > > /etc/passwd.  But beggars can't be choosers I will tackle the array 
> > > piece later. 
> > > 
> > > What the user sees: 
> > > 
> > > Please enter user name(s): 
> > > If more than one separate using commas 
> > > example (single name): evan 
> > > example (multi name): debbie, clint, henry 
> > > 
> > > 
> > > 
> > > So far what broken pieces I have... 
> > > 
> > > #!/usr/bin/perl 
> > > 
> > > 
> > > while($ans !~ /^[a-z]+$/ || $ans !~ /^[a-z]+\,?[a-z]*$/) { 
> > >   errmesg (); 
> > >   $ans = <STDIN>; 
> > > 
> > > }; 
> > > 
> > > sub errmesg { 
> > >   print "\nType user name(s) and press enter:\n"; 
> > >   print "note: if more than one separate using commas\n"; 
> > >   print "example (single name): evan\n"; 
> > >   print "example (multi name): debbie, clint, henry\n"; 
> > > } 
> > > 
> > 
> > 
> > 
> > -- 
> > To unsubscribe, e-mail: [EMAIL PROTECTED] 
> > For additional commands, e-mail: [EMAIL PROTECTED] 
> > 
> 



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED] 
For additional commands, e-mail: [EMAIL PROTECTED] 

Reply via email to