#!/bin/bash
CPU=`sysctl vm.loadavg | awk '{gsub(/\./,"");print$2}'`
if [ "$CPU" -gt 020 ]; then
echo "You system's load average is $CPU, how exciting!"
else
echo "Well, nothing interesting going on here."
fi
-gt: greater than
-lt: less than
change script accordingly. =)
Nick McSpadden wrote:
This is really more of a UNIX question than an ARD question, so sorry
if this is off topic.
I want to set up a repeated job on the macs that checks their load
average and then performs certain tasks based on that. It's easy
enough to do load average checking with the UNIX command "uptime."
I know I can get the load average amount with the UNIX command:
uptime | cut -c 48-49
(so if the load average is 0.18, I'll get 18 as the number).
I then want to test this against a threshold amount, such as 40 (i.e.
if load average goes above 0.4):
In a UNIX shell script, i can set this to:
#!/bin/bash
let LAVG=`uptime | cut -c 48-49`
let THRESHOLD=40
if ( $LAVG > $THRESHOLD)
then
<do stuff....>
else
<do something else....>
fi
Problem is, I can't get the conditional to work right. I know UNIX
variables don't care about their content (they aren't typecasted like
in C/C++), but it seems the comparison is failing. What can I do to
make sure it goes through?
I know the value in $LAVG is being treated arithmetically, because I
can perform arithmetic problems on it (i.e. if $LAVG=50, $LAVG-40
gives me 10, as expected).
Any clues?
--
Nick McSpadden
Schools of the Sacred Heart
Technology Network Assistant