> I am trying to write a perl script to automate
> useradd and passwd by reading a text file containing
> a number of usernames for any version of Solaris.
> 
> I am having difficulties executing passwd in perl
> since it asks for the password interactively. Is
> there a way to get around it by forcing it to reset
> the password non-interactively and automatically?
> 
> Any tips are welcome. Thank you.

It's presumed to be evil to code passwords, since someone can read them in
the code, which may be part of why passwd isn't meant to be able to do what
you ask.  The other of course is that it has to do some termio ioctls to
turn off echoing (and back on again), and those only work on terminals.
So it works against /dev/tty rather than standard input.  And /dev/tty
is invalid if you don't have a controlling terminal (like in a cron or at job).

I don't know if there's a way to do what you want in perl, but there's a
utility called "expect" that can look to an application as if it was a tty,
but actually get its input under script control.

I think "expect" is part of the sfw consolidation, and if installed, would
be in /usr/bin/expect.  There may also be sample scripts for it in
/usr/demo/expect, as well as man pages.

P.S.  just for kicks, I googled for
perl expect
and the very first hit was Expect.pm at cpan.org.  It looks like it lets you
do expect-like things from within your perl script.  So maybe that's what you
want to get., if it's not already there.
--
This message posted from opensolaris.org

Reply via email to