This one is stumping me, I'm sure it must have been done before. I want to automte adding a user with Expect.pm (1.15)

use Expect; use IO::Stty; my $command = "adduser"; my @params = qw( --no-create-home --firstuid 4001 --ingroup clients -- +shell /bin/false --home /home/fred fred); my $exp = Expect->new("$command @params") or die "Cannot spawn $comman +d: $!\n"; $Expect::Exp_Internal = 1; my $timeout = 5; $exp->expect($timeout, [ qr/UNIX password:/ => sub { my $exp = shift; $exp->send("sponge\n"); exp_continue; } ], [ qr/Full Name/ => sub { my $exp = shift; $exp->send("Mr Fred\n"); exp_continue; } ], [ qr/Number|Phone|Other/ => sub { my $exp = shift; $exp->send("\n"); exp_continue; } ], [ qr/correct/ => sub { my $exp = shift; $exp->send("y\n"); } ], );

I run this and get an odd timeout:

Waiting for new data (5 seconds)... adduser: Warning: The home dir you specified does not exist. Adding user `fred'... Adding new user `fred' (4001) with group `clients'. Waiting for new data (5 seconds)... Not creating /home/fred. Waiting for new data (5 seconds)... Enter new UNIX password: Waiting for new data (5 seconds)... sponge Waiting for new data (5 seconds)... TIMEOUT Returning from expect with TIMEOUT or EOF

Sometimes it gets to the password confirm line and sometimes it doesn't.

--
Steve Marvell


In reply to expect and adduser by marvell

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.