I am trying to run "lvs" in a perl script to parse its output.
my $output = `lvs --noheadings --separator : --units m --nosuffix 2>&1`;
my $result = $?;
if ($result != 0 || length($output) == 0) {
printf STDERR "Get list of LVs failed (exit result: %d): %s\n",
$result, $output;
exit(1);
}
printf "SUCCESS:\n%s\n", $output;
When I run the above script from a terminal window it runs fine. If I run via cron it fails:
Get list of LVs failed (exit result: -1):
Note the lack of any output (stdout + stderr)
If I run the same "lvs --noheadings --separator : --units m --nosuffix" command directly in cron, it runs and outputs just fine.
If I modify the perl script to use open3() I also get the same failure with no output.
If I add "-d -d -d -d -d -v -v -v" to the lvs command to enable verbose/debug output I see that when I run the perl script from terminal, but there is no output when run via cron/perl.
I'm running this on RHEL 7.2 with /usr/bin/perl (5.16.3)
Any suggestions???