这个让我挠了挠头。我有一个bash脚本,我试图作为一个nagios插件运行。bash脚本中的字符串比较
从命令行一切都很好,但在nagios下运行时会执行错误的执行路径。在这种情况下,nagios服务器是我的本地盒子。
这是脚本中出现问题的地方。这有点简化,但并不多。示例:
# at the start of the script
threshold_type="above"
# then later on..
check_thresholds() {
if [ "$threshold_type" == "above" ]; then
method_1
else
method_2
fi
}
当check_thresholds
下的nagios称为method_2
运行。从命令行运行(相同的参数,我发誓)method_1
被调用。任何想法可能会发生什么?我应该检查字符串比较不同吗?
[编辑]我愚蠢地忽视提到命令行是从Mac OSX运行,而nagios服务器是盒子上的Ubuntu VM。
该错误与被修改的“threshold_type”的值一致。有没有机会在Ubuntu VM上的脚本有DOS行结尾,这会在'threshold_type'的值结尾处放置一个流浪回车。这会导致比较失败并调用'method_2'。 – chepner 2014-10-16 20:08:44
@chepner不是不可能的,我会仔细检查一下,谢谢你的建议。 – larryq 2014-10-16 20:13:46
我想念一个shebang。 – Cyrus 2014-10-16 20:21:41