Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux LVM lvs命令从cron perl脚本失败,但直接从cron工作_Linux_Perl_Cron_Lvm - Fatal编程技术网

Linux LVM lvs命令从cron perl脚本失败,但直接从cron工作

Linux LVM lvs命令从cron perl脚本失败,但直接从cron工作,linux,perl,cron,lvm,Linux,Perl,Cron,Lvm,我试图在perl脚本中运行“lvs”来解析其输出 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, $ou

我试图在perl脚本中运行“lvs”来解析其输出

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;
当我从终端窗口运行上述脚本时,它运行良好。如果我通过cron运行,它将失败:

Get list of LVs failed (exit result: -1): 
注意缺少任何输出(stdout+stderr)

如果我直接在cron中运行相同的“lvs--noheaders--separator:--units m--nosuffix”命令,它运行和输出都很好

如果我修改perl脚本以使用open3(),我也会在没有输出的情况下得到同样的失败

如果我在lvs命令中添加“-d-d-d-d-v-v-v”以启用详细/调试输出,那么当我从终端运行perl脚本时,我会看到,但是当通过cron/perl运行时,没有输出

我使用/usr/bin/perl(5.16.3)在RHEL7.2上运行这个


有什么建议吗?

尝试使用绝对路径访问
lvs

my $output = `/sbin/lvs --noheadings --separator : --units m --nosuffix 2>&1`;
根据“返回值-1表示启动程序失败或等待(2)系统调用出错(检查$!原因)。”因此没有输出的原因是因为
lvs
没有成功启动


考虑到cron相关问题的通常性质,我认为它无法运行的最可能原因是它不在
cron
使用的
$PATH
上。尝试指定完整路径,如果不起作用,请选中
$用于操作系统的错误消息。

是的,问题是在cron+perl中,$PATH没有设置为include/sbin,其中“lvs”是。因此,指定“/sbin/lvs”可以解决问题。非常感谢。