I have the below script and basically what I want it to do is connect to the various servers. See how many open files there are, and sent an email if its over 50,000. But the last server I need this check for over 400,000. I have a problem with the OR which is not working.
If I run this current script as it is I get the alert email even though none of the limits have been hit. Please help me with my OR statement.
My output from in command line shows:
Alert Server Issue
AlertError S1:6326 S2:6355 S3:6242 S4:7171 S5:4694 S6:5284 S7:3973 S8:308432
The script:
#!/bin/bash
S1_IP=72.15.97.13
S2_IP=72.15.97.14
S3_IP=72.15.97.15
S4_IP=72.15.97.16
S5_IP=72.15.97.17
S6_IP=72.15.97.18
S7_IP=72.15.97.19
S8_IP=72.15.97.20
RESULT1=$(ssh test@$S1_IP lsof | wc -l)
RESULT2=$(ssh test@$S2_IP lsof | wc -l)
RESULT3=$(ssh test@$S3_IP lsof | wc -l)
RESULT4=$(ssh test@$S4_IP lsof | wc -l)
RESULT5=$(ssh test@$S5_IP lsof | wc -l)
RESULT6=$(ssh test@$S6_IP lsof | wc -l)
RESULT7=$(ssh test@$S7_IP lsof | wc -l)
RESULT8=$(ssh test@$S8_IP lsof | wc -l)
ERROR_COUNT=0
if [[ $RESULT1 || $RESULT2 || $RESULT3 || $RESULT4 || $RESULT5 || $RESULT6 || $RESULT7 -gt 50000 ]] || [[ $RESULT8 -gt 400000 ]]
then
ERRORS[$ERROR_COUNT]="AlertError"
ERROR_COUNT=$(($ERROR_COUNT+1))
fi
if [ $ERROR_COUNT -gt 0 ]
then
[email protected]
SUBJECT="Over 50,000"
BODY='Alert Server Issue'
CNT=0
while [ "$CNT" != "$ERROR_COUNT" ]
do
BODY="$BODY ${ERRORS[$CNT]}
S1:$RESULT1
S2:$RESULT2
S3:$RESULT3
S4:$RESULT4
S5:$RESULT5
S6:$RESULT6
S7:$RESULT7
S8:$RESULT8"
CNT=$(($CNT+1))
done
echo $SUBJECT
echo $BODY
echo $BODY | mail -s "$SUBJECT" -a "From: [email protected]" $EMAIL
else
echo "I can handle it
S1:$RESULT1
S2:$RESULT2
S3:$RESULT3
S4:$RESULT4
S5:$RESULT5
S6:$RESULT6
S7:$RESULT7
S8:$RESULT8"
fi
$cwd
. Anything you see, show us. Add aset -vx
to the top of the script, show us what you get then. Do anything you can think of to get us more pertinent information.