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;
-
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.