setting a user passwd

------=_NextPart_000_0017_01C58E2E.B5569F80
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

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 [at] mail victor]$ perl passwd.pl victor1

#!/usr/bin/perl
$usuario=3D$ARGV[0];
$passwd=3D"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


------=_NextPart_000_0017_01C58E2E.B5569F80--
Victor Pezo [ Fr, 22 Juli 2005 02:59 ] [ ID #891114 ]

RE: setting a user passwd

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 [at] 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";

--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
<http://learn.perl.org/> <http://learn.perl.org/first-response>
Bob Showalter [ Fr, 22 Juli 2005 14:47 ] [ ID #891124 ]
Perl » gmane.comp.lang.perl.beginners » setting a user passwd

Vorheriges Thema: RE: Replacing printf by print
Nächstes Thema: Replcaing printf by print