In message <[EMAIL PROTECTED]>
          Darren Wanner <[EMAIL PROTECTED]> wrote:
> 
> I'm trying to write a simple script that takes a list of users from a file
> and creates a user account for them, using the useradd script.  The system
> I'm doing this on is Solaris 8.  When I run the script I get the following
> error.  It seems as if it's not accepting the variable in the command
> line.  I'm pretty new to all of this so any help would be greatly
> appreciated.
> 
> Error Message:
> 
> UX: useradd: ERROR: invalid syntax.
> usage:  useradd [-u uid [-o] | -g group | -G group[[,group]...] | -d dir |
>                 -s shell | -c comment | -m [-k skel_dir] | -f inactive |
>                 -e expire | -A authorization [, authorization ...] |
>                 -P profile [, profile ...] | -R role [, role ...]]
>                 -p project [, project ...] login
>         useradd -D [-g group | -b base_dir | -f inactive | -e expire
>                 -A authorization [, authorization ...] |
>                 -P profile [, profile ...] | -R role [, role ...]] |
>                 -p project
> sh: -m: not found

This is actually two different error messages.

> 
> Simple add user script:
> 
> #!/usr/bin/perl

No '-w', no use strict.

> open(FILE,"users.log");

You aren't checking whether you opened the file successfully.

> @users=<FILE>;

Whenever you read a whole file into an array only to then iterate over that
array once you should ask yourself if you need to use the array.

> foreach $users (@users) {

Just a stylistic point, $user would be a better choice of variable name as it
will only contain one user at a time.

This is your real problem. $user will still have the newline character at
this point, so the following command will actually have a newline embedded in
it. Use chomp() to remove it.

> `useradd -g 201 -d /userhome/$users -m $users`;

You are not doing anything with the result of the command so using backticks
is inappropriate, use the system() command.

> }
> print "done.\n";
> 

#!/usr/bin/perl -w

use strict;

open(FILE,"users.log") or die "Unable to read users file: $!\n";
while ( my $user = <FILE> )
{
  chomp($user);
  system("useradd","-g","201","-d","/userhome/$user","-m",$user);
}
close(FILE);

Dave. 
-- 
No, the fact that it's an infinite loop doesn't mean the program doesn't
work; it just entered a state with which I was previously unfamiliar.
     Calum - Acorna, A.McCaffrey & M.Ball

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

Reply via email to