Liam Delahunty: Home Tips Web Contact
Recommended laptop
under £500
.

Think I deserve a present? See my Amazon Wish List

Bash Shell - Load Average Cron Script

#!/bin/bash
loadavg=`uptime | awk '{print $10+0}'`
# bash doesn't understand floating point
# so convert the number to an interger
thisloadavg=`echo $loadavg|awk -F \. '{print $1}'`
if [ "$thisloadavg" -ge "2" ]; then
 echo "Busy - Load Average $loadavg ($thisloadavg) "
 top -bn 1
else
 echo "Okay - Load Average $loadavg ($thisloadavg) "
fi

Thanks to Pierre Forget of st-donat.com for suggesting the awk '{print $10+0}' modification to strip the last comma from uptime.

Share this!