http://perlmonks.org/?node_id=884178
And indeed, I found that utilizing IO::Select to only read/write to known ready filehandles that got rid of the bizarre errors. Then it was just a matter of finding the correct voodoo to keep the program from prompting me (the user) for a password, ever, which was basically a matter of appending a bunch of \n's to the password writing process. Lame, yes--but it works :-)
If anyone knows of more elegant ways to do this, that would be great, but this works:
#!/usr/bin/perl use strict; use warnings; use Net::OpenSSH; use IO::Select; foreach my $host (qw/rasto@172.16.0.102 rasto@172.16.0.100/) { print "doing $host\n"; my $pass2 = 'orange!'; my $ssh = Net::OpenSSH->new($host); $ssh->error and die "unable to connect to remote host: " . $ssh->e +rror; $ssh->system('sudo -K'); my( $in, $out, $err, $pid ) = $ssh->open3("sudo ls"); my $sel = new IO::Select( $in, $err ); my( @readready, @writeready ); foreach my $fh ( $sel->can_write(5) ) { if( $fh == $in && fileno $in ) { syswrite( $in, $pass2 . "\n\n\n\n\n\n" ); } } my @output; foreach my $fh ( $sel->can_read(5) ) { print "inside foreach\n"; @output = <$err>; } if( grep { $_ =~ /Sorry/gsm } @output ) { print "fail\n"; } else { print "success!\n"; } close $in; close $out; close $err; }
In reply to Re: Trapping sudo failures via Net::OpenSSH
by rastoboy
in thread Trapping sudo failures via Net::OpenSSH
by rastoboy
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |