3

I'm trying to create a simple script that takes an average load percentage of the CPU each minute. I'm doing this by using the sar command from the sysstat package.

Here is my current code:

#!/bin/bash
sar -u 1 10 | grep Average > /custom/tmp/idlefile
idleval=`awk '{print $8}' /custom/tmp/idlefile`
rm /custom/tmp/idlefile
rm -rf /custom/idlepercentage/*
touch /custom/idlepercentage/$idleval
exit 0

The problem is, the only thing it can do right now is output an idle percentage. I'd like it to simply output a load percentage.

I attempted to do this by:

loadval=100.00-`echo $idleval`

but it shouts at me and won't do what I ask it to do.

It seems like it wont do the basic arithmetic to do 100% - idle percent to give load percent.

6

This should work:

loadval=$(sar -u 1 10 | awk '{print 100-$8}')
1
  • 1
    Works, and wow was more simple than i thought, thanks! – Matt Elvidge Mar 2 '15 at 12:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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