sub checksudo { my ($ssh, $ip, $pass) = @_; #$ssh is the successfully created openssh object, $pass is the user's sudo password my $system = $ssh->system ('sudo -K') or return "failed to sudo -K: $!\n"; #ensure we are prompted for a password my ( $pty, $pid ) = $ssh->open2pty( "sudo -p 'configtest:' bash 2>&1") or return "failed to attempt sudo bash: $!\n"; my $expect = Expect->init($pty); #sleep 1; #$expect->send ($pass . "\n"); $expect->expect(2, [ qr/configtest:/ => sub { my $expect =shift; $expect->send($pass . "\n"); exp_continue;} ], [ qr/Sorry/ => sub { my $expect=shift; print "Failed\n"; exp_continue; } ], ); #$expect->interact(); return; }