Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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.


In reply to Re: /usr/bin/passwd by plaid
in thread /usr/bin/passwd by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (5)
As of 2024-04-19 13:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found