我是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
有人可以帮我解决这个问题吗?
答案 0 :(得分:0)
除了已发布的(正确)评论之外:您可以从您的列表中看到,如果$ ARG不是普通文件,则会显示该消息。
顺便说一下,我建议输出$ ARG的值。