#!/bin/bash
# Disk Space Monitoring for more than 96%
# Aand shuting down servers
# Declare Variebles
used_space=0
mount_point="/apps/"
threshold=$96%
DOMAIN_HOME=/apps/oracle/product/Middleware/user_projects/domains/cbs_idm_dom
EMAIL_ADDR=user@host
MW_BASE=/apps/oracle/product/Middleware
used_space=`df -k $mount_point | grep % | awk {'print $4'} | sed 's/%//g'`
#print "Free space available under \"$mount_point\" is `expr 100 - $used_space`%.\n"
if [ $used_space >= $threshold ]
echo $MESSAGE | mailx -s "Alert:Server disk is full - shutting down server." $EMAIL_ADDR
#sleep 60
then
#Shutdown OID in this host
# STOP
source $MW_BASE/wlserver_10.3/server/bin/setWLSEnv.sh
#STOP OPMN
#$MW_BASE/idm_inst/bin/opmnctl stopall > /apps/oracle/product/Middleware/scripts/logs/stop_idm_inst.log &
#$MW_BASE/idm_sync/bin/opmnctl stopall > /apps/oracle/product/Middleware/scripts/logs/stop_idm_sync.log &
#Stop Weblogic
$DOMAIN_HOME/bin/stopManagedWebLogic.sh wls_ods1 > /apps/oracle/product/Middleware/scripts/logs/stop_wls_ods2.log &
else
echo "INVALID OPTION"
fi;
答案1
错误的原因是这一对行
threshold=$96%
...
if [ $used_space >= $threshold ]
第一个将阈值设置为完全不同于我怀疑你正在做的事情的阈值。主要是因为您没有引用该字符串,但部分原因是$
这里有一个甚至没有语义意义的:
threshold=$96%
echo ">$threshold<" # >6%<
我省略的代码...
设法设置了used_space=97
,因此您可以进行比较,这根本不是真正的比较。将测试的输出>
重定向到文件中=
,然后将以下内容作为测试的一部分进行评估:
[ 97 6% ]
其中吐出-bash: [: 97: unary operator expected
。您可能正在寻找-ge
运营商(请参阅man bash
或什至man test
了解您可以使用的运营商的详细信息)。