Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top
#!/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;
share|improve this question

closed as unclear what you're asking by dhag, vonbrand, chaos, mdpc, G-Man Oct 21 '15 at 22:30

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question.If this question can be reworded to fit the rules in the help center, please edit the question.

7  
There's a bunch of syntax errors in this script. It would be best if you could reduce it to a snippet that exhibits the single issue that you want help with. Or, at least, edit your question to paste the exact error message that you get. – dhag Oct 21 '15 at 20:49
    
@dhag fwiw the exact error message was in the title – roaima Oct 24 '15 at 20:19

The cause of the error is this pair of lines

threshold=$96%
...
if [ $used_space >= $threshold ]

The first one sets threshold to something entirely unlike what I suspect you thing it's doing. Mainly because you haven't quoted the string, but partly because there's a $ in here that doesn't even make semantic sense:

threshold=$96%
echo ">$threshold<"    # >6%<

The ... code I've omitted manages to set used_space=97, so you then come to the comparison, which isn't really a comparison at all. The > redirects output from the test into the file = and then leaves the following to be evaluated as part of the test:

[ 97 6% ]

which spits out -bash: [: 97: unary operator expected. You were probably looking for the -ge operator (see man bash or even man test for details of the operators available to you).

share|improve this answer
    
or help test, since he is probably getting bash's built-in test – drewbenn Oct 21 '15 at 21:05
    
@drewbenn any of these will provide information about the more standard operators such as -ge. – roaima Oct 21 '15 at 21:06

Not the answer you're looking for? Browse other questions tagged or ask your own question.