【发布时间】:2015-06-03 07:38:40
【问题描述】:
我是 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
谁能帮我解决这个问题?
【问题讨论】:
-
这是 shell 脚本,不是 perl。你可以在代码的第一行看到它:
#!/bin/sh。 -
这不是错误,脚本正在打印该行。