Re: adduser without ncurses?
From: Theorem (Theorem_at_Axiometric.NOSPAMPLEASE.org)
Date: 06/20/04
- Previous message: jpd: "Re: adduser without ncurses?"
- In reply to: Erica: "adduser without ncurses?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sun, 20 Jun 2004 07:30:59 -0400
Erica wrote:
> (I may have accidently posted this twice, if so, I apologize)
>
> Hi,
>
> I wrote a script to add a whole bunch of users to a FreeBSD box using input from
> a file. However, I need something that works like adduser or useradd
> without ncurses, that is, without prompting for input. Something that
> allows me to just place all the arguments on a single line so that I can
> run it in an awk loop. If anyone knows of such a thing, I would be ever
> grateful for your assistance.
I do this with a perl script that reads the file and then calls pw to
create the account (without a password). The perl script then writes a
temporary expect script that when run will set the password, then the
perl script runs the expect script, and finally the perl script
unlinks the expect script.
Here's some perl code that does the account creation and password
changing. I leave the file reading and variable setting to you. You
may want other switches in your pw command as well.
#!/usr/bin/perl
# loop to read file and set variables and then...
system("/usr/sbin/pw useradd -n $user -c $name -m -s $shell")
== 0 or die "Error creating $user account: $?";
open PWC, ">pwc"
or die "Could not write $user expect script: $?";
print PWC <<EOL;
#!/usr/local/bin/expect
set argv $user
spawn -noecho passwd [lindex \$argv 0]
expect "Changing local password for $user."
send ""
expect "password:"
send "$pass\r"
expect "password:"
send "$pass\r"
expect eof
EOL
close PWC;
chmod 0750, pwc;
system("./pwc >> /dev/null")
== 0 or die "Error setting $user pwd: $?";
unlink pwc;
- Previous message: jpd: "Re: adduser without ncurses?"
- In reply to: Erica: "adduser without ncurses?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|