Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Perl Beginners > Re: deleting a ...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 2 of 4 Topic 11045 of 11518
Post > Topic >>

Re: deleting a user name from a file

by rob.dixon@[EMAIL PROTECTED] (Rob Dixon) May 9, 2008 at 06:56 PM

Lokeey wrote:
> 
> I'm writing this script to remove users from a file, the sudoers file,
to be
> more specific.
> 
> Here is what I have so far, not sure where to go from here.
> 
> *#!/usr/bin/perl -w

There's a star before your #! Is it a typing mistake?

Also,

  use strict;

or there is little point in declaring variables with 'my'. And

  use warnings;

is better than the -w command-line option.

> # this script removes a user from sudoers file

I suggest you write a simple usage help in here, for instance

die <<USAGE unless @[EMAIL PROTECTED]
  This program should be run with command-line parameters like this:
    :
    :
USAGE

> my $sites = $ARGV[0];
> my $user = $ARGV[1];

Fine. But you don't use $sites or $user again. What does your program do
exactly?

> for my $site ($#ARGV[1]){
>   open FILE, "$_/local/etc/sudoers" or die "cannot open sudoers for
$sites: $!";

You have written a 'for' iterator, but its list is $#ARGV[1] which doesn't
make
any sense. I doubt if it will compile. Was $ARGV[0] supposed to be a list
of
sites somehow?

> print "Enter username you wish to remove from $sites sudoers.\n";
> 
>   while (<FILE>) {s/$_//}
>   close FILE;
> }*

(Ah, and another star. Delimiters for pasted code somehow?)

You prompt for a username, even though you have already used $ARGV[1] for
$user.
And you don't read from STDIN to see what the user typed in response to
the prompt.

I suggest you forget about @[EMAIL PROTECTED]
 and prompting for and retrieving input.
Hard
code a case where there is only a single site and username to be removed
and get
that working, with our help as necessary. Then you can expand your program
to
take parameters and prompt for input if that is what you want.

HTH,

Rob
 




 4 Posts in Topic:
deleting a user name from a file
lokeey@[EMAIL PROTECTED]   2008-05-09 07:35:03 
Re: deleting a user name from a file
rob.dixon@[EMAIL PROTECTE  2008-05-09 18:56:35 
Re: deleting a user name from a file
rob.dixon@[EMAIL PROTECTE  2008-05-09 20:40:00 
Re: deleting a user name from a file
lokeey@[EMAIL PROTECTED]   2008-05-09 13:49:13 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Thu Jul 24 13:05:35 CDT 2008.