你好,我的脚本没有在服务器端显示正确的退出代码。
SERVICENAME=`/etc/init.d/$NAME status| awk '{print $NF}' | sed 's/\.//g' | grep -i running | sed 's/\s//g'|tail -n 1`
if [ "${SERVICENAME}" == "Running" -o "${SERVICENAME}" == "running" ]
then
STATUS="OK";
EXITSTAT=0;
elif [ "${SERVICENAME}" != "Running" -o "${SERVICENAME}" != "running" ]
then
STATUS="CRITICAL";
EXITSTAT=2;
else
STATUS="WARNING";
EXITSTAT=1;
fi
echo "$STATUS- Service $NAME $EXITSTAT |Service $NAME=0;2;3"
exit $EXITSTAT
答案1
我发现您的脚本中存在一些错误。如果您希望将命令的值赋予 SERVICENAME,则必须在其前后添加反引号:
SERVICENAME=`/etc/init.d/$NAME status| awk '{print $NF}' | sed 's/\.//g' | grep -i unning | sed 's/\s//g'|tail -n 1`
if
和之间then
必须有一个分号:
if [ "${SERVICENAME}" == "Running" -o "${SERVICENAME}" == "running" ]; then STATUS="OK"; EXITSTAT=0; elif [ "${SERVICENAME}" != "Running" -o "${SERVICENAME}" != "running" ]; then STATUS="CRITICAL"; EXITSTAT=2; else STATUS="WARNING"; EXITSTAT=1; fi
瞧瞧:
[root@test ~]# ./script
OK- Service slapd 0 |Service slapd=0;2;3 exit 0