gpt4 book ai didi

linux - 严重 - 文件不存在!使用perl脚本监控apache日志时出错

转载 作者:太空宇宙 更新时间:2023-11-04 06:01:03 27 4
gpt4 key购买 nike

我是 Perl 新手。我收到此错误:

CRITICAL : "file does not exist"

当我尝试运行脚本来通过 Nagios 监视 httpd 错误日志时。

#!/bin/sh
# Created by Brian Weber <brian@bdweber.net> Jan 5, 2012
# check_file_md5s
# Checks the md5sum of a particular file against one stored in a predetermined list.
# No arguments will return usage.
# Please read usage statement for further detail.

# Modeled after / inspired by / replacing check_file_md5s by Stephen Berg, et al.

VERSION=0.1

MD5=`which md5sum`
MD5_LIST="/usr/local/nagios/md5s"


function check_file_md5() {
if [ -f $ARG ]; then
if [ `grep $ARG $MD5_LIST | wc -l` -eq 1 ]; then
if [ `grep $ARG $MD5_LIST | cut -d\ -f1` = `$MD5 $ARG | cut -d\ -f1` ]; then
echo OK
exit 0
else
echo "WARNING - md5sum does not match! Rebuilding so the next check will match."
rebuild_md5_list
exit 2
fi
else
echo "WARNING - md5sum is not in list. Adding for you now."
echo `$MD5 $ARG` >> $MD5_LIST
exit 1
fi
else
echo "CRITICAL - file does not exist!"
exit 2
fi
}

function show_usage() {
echo ""
echo " $0 - plugin for checking arbitrary md5sum against a predetermined list."
echo " This list lives at $MD5_LIST"
echo " New files need to be added by doing the following command:"
echo " $MD5 /path/to/file >> $MD5_LIST"

echo ""
echo " Usage: $0 /path/to/file"
echo " $0 --help"
echo ""
echo " Version: $VERSION"
echo ""
}

function rebuild_md5_list() {
MD5_DATE=${MD5_LIST}.`date +%Y%m%d`
mv $MD5_LIST $MD5_DATE

for FILE in `cat $MD5_DATE | awk '{ print $2 }' | sort | uniq | xargs`; do
md5sum ${FILE} >> $MD5_LIST
done
}

if [ -z "$1" ]; then
show_usage
exit 2
fi

case $1 in
--help)
show_usage
exit 0
;;
*)
ARG=$1
check_file_md5
;;
esac

有人可以帮我解决这个问题吗?

最佳答案

除了已经发布的(正确的)评论之外:您可以从列表中看到该消息已显示,前提是 $ARG 不是普通文件。

顺便说一句,我建议输出 $ARG 的值。

关于linux - 严重 - 文件不存在!使用perl脚本监控apache日志时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29343669/

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