in reply to Read Pipe, Never Enters While Loop

open (PRM, "-|", $NE_obj->cmd("ssh $activepilotrcs reboot ; tailer PRM +"));

Where in the documentation of Control::CLI did you find that usage?

To me it seems that ->cmd returns a string of the command output, not a filehandle to be read from. That's also what the documentation says:

Sends a CLI command to host and returns output data

Maybe consider checking whether your open call succeeds at all:

open (PRM, "-|", $NE_obj->cmd("ssh $activepilotrcs reboot ; tailer PRM +")) or die "Couldn't open filehandle : $!";

But if you're using ssh anyway, why not run the commands directly through it?

my $output = `(ssh $activepilotrcs reboot ; tailer PRM) |`;

Or, instead, use Net::SSH::Any and use that to send the SSH commands yourself.

Replies are listed 'Best First'.
Re^2: Read Pipe, Never Enters While Loop
by ImJustAFriend (Scribe) on Jun 02, 2017 at 19:43 UTC

    Where in the documentation of Control::CLI did you find that usage?

    That is the syntax for sending a command to the remotely connected device. That part works fine...

    Maybe consider checking whether your open call succeeds at all

    I can see my open works in the logs created by Control::CLI. I can see in the input and debug logs the output of the tailer command.

    But if you're using ssh anyway, why not run the commands directly through it?

    In earlier code (not shown), I am connected to another blade on the machine already. The command in my open call is so I can SSH from the already established connection to another blade on the server. Straight SSH won't work in this case...

    Thank you Corjon for the feedback - I truly appreciate it!!

      What fails is your call to open.

      If you don't check that, you will wonder forever why Perl does not seem to read from that file.

      What works is your call to ->cmd, but that doesn't return a filehandle but the output of the command you run on the remote end.

        I added the code to die if open failed, and it doesn't die. Looks to me like open is working?

        open (PRM, "-|", $NE_obj->cmd("ssh $activepilotrcs reboot ; tailer PRM +")) or die "Could not open PRM: $!\n";; while (<PRM>) { print "DEBUG: $_\n"; if ($_ =~ m/.*FAILED HEARTBEAT.*/sxi) { print "$spacer $spacer $spacer $spacer Alarm Received That Act +ive Pilot Has Gone Down...\n"; } elsif ($_ =~ m/.*STARTING OA&M LEAD TRANSITION.*/sxi) { print "$spacer $spacer $spacer $spacer Standby Pilot $stdbypil +otrcs Has Started Transitioning To Active...\n"; } elsif ($_ =~ m/.*FAILOVER INITIALIZATION COMPLETED.*/sxi) { print "$spacer $spacer $spacer $spacer Standby Pilot $stdbypil +otrsc Has Transitioned To Active...\n"; $NE_output = $NE_obj->cmd("\003"); last; } else { next; } }