Home > Archive > PERL Beginners > July 2005 > setting a user passwd
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
setting a user passwd
|
|
| Victor Pezo 2005-07-24, 8:29 pm |
| Hi, I am developing a program that sets passwd for any user but i dont want the operator sets the passwd. I want to give it as a result of a function
[victor@mail victor]$ perl passwd.pl victor1
#!/usr/bin/perl
$usuario=$ARGV[0];
$passwd="PASSWDGENERATEBYOTHERFUNCTION"
`sudo /usr/sbin/useradd -c $usuario -s /sbin/nologin $usuario`;
`sudo /usr/bin/passwd $usuario`;
I could add the user, but in the set passwd line.
When I use this script always I have a prompt of password assigment that I dont want. Could you give me some light of what can I do?
Thanks in advance,
Victor
| |
| Bob Showalter 2005-07-24, 8:29 pm |
| Victor Pezo wrote:
> Hi, I am developing a program that sets passwd for any user but i
> dont want the operator sets the passwd. I want to give it as a result
> of a function
>
> [victor@mail victor]$ perl passwd.pl victor1
>
> #!/usr/bin/perl
> $usuario=$ARGV[0];
> $passwd="PASSWDGENERATEBYOTHERFUNCTION"
> `sudo /usr/sbin/useradd -c $usuario -s /sbin/nologin $usuario`;
> `sudo /usr/bin/passwd $usuario`;
>
> I could add the user, but in the set passwd line.
> When I use this script always I have a prompt of password assigment
> that I dont want. Could you give me some light of what can I do?
The classic answer to this is to use the Expect module, because passwd(1)
historically has read only from /dev/tty.
However, if you're on Linux, passwd(1) has a --stdin option that lets you
supply the password via standard input. So you could write something like
(untested):
system "echo \Q$passwd\E | sudo /usr/bin/passwd --stdin \Q$usario\E";
|
|
|
|
|