Fellow Monks!

I'm working on this for over 2 days now to no avail, and I must admit IPC is one of my weakest fields. I have got the task to automate resetting passwords without user input on AIX /w HACMP. Although I'm allowed to test as root user, I'm not allowed to install any modules like Expect.

When I run the external command over the command line, I type in the passwords which get not displayed and all is OK:

# /usr/es/sbin/cluster/sbin/cl_chpasswd -cspoc -f -k testuser Changing password for "testuser" testuser's New password: Enter the new password again: # echo $? 0 #

When run by my test script and hitting <Ctrl+C> after the second password display:

# ./test.pl testuser's New password: testpass testpass 3004-657 Terminating from signal. # echo $? 130 #

When run by my test script and typing in the password followed by <ENTER> after second password display:

# ./test.pl testuser's New password: testpass testpass Enter the new password again: # echo $? 0 #

So I can see the passwords get printed but the external program doesn't get the input.
Any ideas?
Thanks in advance!
Below my test script:

#!/usr/bin/perl use strict; use warnings; $ENV{ODMDIR} = '/etc/objrepos/'; # needed for external program my $user = 'testuser'; my $password = 'testpass'; my $cmd = "/usr/es/sbin/cluster/sbin/cl_chpasswd -cspoc -f -k $user"; #print $cmd, $/x2; # verified - OK use IPC::Open2; my $pid = open2(*Reader, *Writer, $cmd); # No success with following variations: #my $pid = open2(*Reader, *Writer, "$cmd </dev/tty"); #my $pid = open2(*Reader, *Writer, "$cmd </dev/tty >/dev/tty"); $| = 1; # Verify device: #use POSIX; #my $tty = POSIX::ctermid(); #print "\nTTY: '$tty'\n\n"; # prints: TTY: '/dev/tty' local *STDOUT; open( STDOUT, ">>/dev/tty" ); # wait until external program is ready sleep 5; # Enter password: #print Writer "$password\n"; # neither displayed nor accepted as input print "$password\n"; # will be displayed but not accepted as input sleep 2; # Repeat password: #print Writer "$password\n"; print "$password\n"; waitpid $pid, 0; close Reader; close Writer;


In reply to Submitting password changes to external program by Dietz

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.