gpt4 book ai didi

linux - 为什么不在 check_flexlm.pl 中检查/usr/local/bin/?来源包括

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:43:58 26 4
gpt4 key购买 nike

即使我有 /usr/local/bin/lmstat,下面的脚本总是失败并显示 Cannot find "lmstat"

谁能看出为什么会这样?

use strict;
use Getopt::Long;
use vars qw($opt_V $opt_h $opt_F $opt_t $verbose $PROGNAME);
use FindBin;
use lib "$FindBin::Bin";
use lib '/usr/lib64/nagios/plugins';
use utils qw(%ERRORS &print_revision &support &usage);

$PROGNAME="check_flexlm";

sub print_help ();
sub print_usage ();

$ENV{'PATH'}='/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin';
$ENV{'BASH_ENV'}='';
$ENV{'ENV'}='';

Getopt::Long::Configure('bundling');
GetOptions
("V" => \$opt_V, "version" => \$opt_V,
"h" => \$opt_h, "help" => \$opt_h,
"v" => \$verbose, "verbose" => \$verbose,
"F=s" => \$opt_F, "filename=s" => \$opt_F,
"t=i" => \$opt_t, "timeout=i" => \$opt_t);

if ($opt_V) {
print_revision($PROGNAME,'2.2.1');
exit $ERRORS{'OK'};
}

unless (defined $opt_t) {
$opt_t = $utils::TIMEOUT ; # default timeout
}


if ($opt_h) {print_help(); exit $ERRORS{'OK'};}

unless (defined $opt_F) {
$opt_F = $ENV{'LM_LICENSE_FILE'};
unless (defined $opt_F) {
print "Missing license.dat file\n";
print_usage();
exit $ERRORS{'UNKNOWN'};
}
}
# Just in case of problems, let's not hang Nagios
$SIG{'ALRM'} = sub {
print "Timeout: No Answer from Client\n";
exit $ERRORS{'UNKNOWN'};
};
alarm($opt_t);

my $lmstat = $utils::PATH_TO_LMSTAT ;
unless (-x $lmstat ) {
print "Cannot find \"lmstat\"\n";
exit $ERRORS{'UNKNOWN'};
}

最佳答案

永远不要假设您知道某物是什么。尝试打印路径以验证它是否如您所想:

unless (-x $utils::PATH_TO_LMSTAT ) {
print qq/Cannot find "lmstat" at <$utils::PATH_TO_LMSTAT>\n/;
exit $ERRORS{'UNKNOWN'};
}

如果 $utils::PATH_TO_LMSTAT 是相对路径(例如 lmstat 本身),则 -x 会在当前目录中查找.如果是完整路径,则可能是您输入的字符串有误。

请注意,您的选项处理可能不那么笨拙,因为您可以在同一键中为选项指定多个名称:

GetOptions(
"V|version" => \$opt_V,
"h|help" => \$opt_h,
"v|verbose" => \$verbose,
"F|filename=s" => \$opt_F,
"t|timeout=i" => \$opt_t,
);

Mastering Perl 的“安全编程技术”一章讨论了调用外部程序的程序的许多令人头疼的问题。

关于linux - 为什么不在 check_flexlm.pl 中检查/usr/local/bin/?来源包括,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48709038/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com