[Gllug] Simple Bash Script

william pink will.pink at gmail.com
Mon Jun 2 10:10:16 UTC 2008


Well I have made the suggested adjustments but it still doesn't appear to
work

#!/bin/bash

# Script for debbie to check system load and remove from cluster if higher
than 8.0

TEMPFILE="$(mktemp)"
NOTIFY="3"
HOST=`hostname`
#RCLUSTER=`/usr/local/bin/in-cluster no`
#load at 1 minute
TRUE="1"
LOADAVG=$(cut -f1 -d' ' /proc/loadavg)

#input in tempfile
echo "Load average to high removed from cluster, Load currently at $LOAD
allowed limit $NOTIFY." > $TEMPFILE

# Compare results to benchmark
RESULT=$(echo "$LOADAVG >= $NOTIFY" | bc)

# IF so do your thing

if [ "$RESULT -eq $TRUE" ]; then
    echo "test failed!"
    else echo "No problem to report"
fi

rm -f $TEMPFILE

Does the last if statement look correct?

Thanks,
Will


On Mon, Jun 2, 2008 at 11:00 AM, Anthony Newman <anthony.newman at ossified.net>
wrote:

> Iain Gray wrote:
> > if [ "$RESULT == $TRUE" ];
> > Isn't BASH silly in that it uses == for string comparison and -eq for
> integer?
> >
> > So this line should be written
> >
> > if [ $RESULT -eq $TRUE ]
>
> Pretty much.
>
>
> >> LOAD=`uptime | sed -e "s/.*load average: \(.*\...\), \(.*\...\),
> >> \(.*\...\)/\1/" -e "s/ //g"`
>
> LOADAVG=$(cut -f1 -d' ' /proc/loadavg)
>
>
>
> ;)
>
>
> Ant
> --
> Gllug mailing list  -  Gllug at gllug.org.uk
> http://lists.gllug.org.uk/mailman/listinfo/gllug
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.lug.org.uk/pipermail/gllug/attachments/20080602/9d9b777c/attachment.html>
-------------- next part --------------
-- 
Gllug mailing list  -  Gllug at gllug.org.uk
http://lists.gllug.org.uk/mailman/listinfo/gllug


More information about the GLLUG mailing list