Hello All,<br><br>I have a script that checks for system load then sends a email if it is over a certain threshold ( Its a cut down version from the one on Nixcraft ) <br>Here is the script <br><br><br>#!/bin/bash<br><br># Script to check system load and remove from cluster if higher than 6.0<br>
<br>TEMPFILE="$(mktemp)"<br>NOTIFY="6.0"<br>HOST=`hostname`<br>RCLUSTER=`/usr/local/bin/in-cluster no`<br>#load at 1 minute<br>TRUE="1"<br>LOAD=`uptime | sed -e "s/.*load average: \(.*\...\), \(.*\...\), \(.*\...\)/\1/" -e "s/ //g"`<br>
<br>#input in tempfile<br>echo "Load average to high removed from cluster, Load currently at $LOAD allowed limit $NOTIFY." > $TEMPFILE<br><br># Compare results to benchmark<br>RESULT=$(echo "$LOAD > $NOTIFY" | bc)<br>
<br># IF so do your thing<br><br>if [ "$RESULT == $TRUE" ]; then<br> $RCLUSTER<br> mail -s "$HOST has been removed from the cluster" "$EMAIL" < $TEMPFILE<br>fi<br><br>rm -f $TEMPFILE<br>
<br>What I am having problems is bc will return back the value 0 but it will still execute the commands <br><br>here is the bash -x output <br><br>root@thebrain:/home/will/scripts# bash -x loadtest.sh <br>+ bash -x loadtest.sh<br>
++ mktemp<br>+ TEMPFILE=/tmp/tmp.xtzco30283<br>+ NOTIFY=3<br>++ hostname<br>+ HOST=thebrain<br>+ TRUE=1<br>++ uptime<br>++ sed -e 's/.*load average: \(.*\...\), \(.*\...\), \(.*\...\)/\1/' -e 's/ //g'<br>+ LOAD=2.19<br>
+ echo 'Load average to high removed from cluster, Load currently at 2.19 allowed limit 3.'<br>++ echo '2.19 >= 3'<br>++ bc<br>+ RESULT=0<br>+ '[' '0 == 1' ']'<br>+ echo test then<br>
test then<br>+ echo 'test failed!'<br>test failed!<br>+ rm -f /tmp/tmp.xtzco30283<br>++ echo -ne '\033]0;root@thebrain: /home/will/scripts\007'<br><br>Any suggestions gratefully received<br><br>Cheers,<br>
Will <br><br>P.S Of course a easier way to do it would be for it to just check the RESULT variable and see if it is a 1 or 0 and just act upon that but I would like to get this method working. <br>