Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

Re: /usr/bin/passwd

by plaid (Chaplain)
on Aug 02, 2000 at 23:59 UTC ( #25831=note: print w/replies, xml ) Need Help??

in reply to /usr/bin/passwd

You probably want to take a look at the Expect module, which will let you handle the program as if you were typing it from the command line. Generally, sleeping like that isn't a safe way to go, as you have no idea whether the program is ready for input or not, and no way of verifying that the input it's prompting for is the input you're about to give it. Expect will let you wait for a certain prompt, such as (on my box)
(current) UNIX password:
Alternatively, you could take a look at IO::Tty, and use it to set up a pty, which will make the passwd program behave as if you were sitting at a terminal, but this is basically what Expect is doing behind the scenes.

The problem you were running into may be related to OS buffering issues. You might try something like (code taken from Programming Perl):

select((select(ADD), $| = 1)[0]);
which would turn on autoflushing on the ADD filehandle. I'd still recommend using Expect though, as it provides a much more robust and flexible way to accomplish your goal.

Update: I should have looked around a bit for this first, but you also might want to take a look at Unix::PasswdFile and/or Passwd::Solaris.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://25831]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (5)
As of 2022-01-23 08:31 GMT
Find Nodes?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:

    Results (63 votes). Check out past polls.