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

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
 echo "Okay - Load Average $loadavg ($thisloadavg) "

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

Share this!