title: Is this the faster way to test cpu load using shell scripting?
body: <p>I'm relatively new to shell scripting and I'm in the process of writing my own health checking scripts using bash.</p>
  
  <p>Is the following script to test cpu load the best I can have in terms of performance, readability and maintainability?</p>
  
  <pre><code>#!/bin/sh
  
  getloadavg5 () {
    echo $(cat /proc/loadavg | cut -f2 -d' ')
  }
  
  getnumcpus () {
    echo $(cat /proc/cpuinfo | grep '^processor' | wc -l)
  }
  
  awk \
    -v failthold=0.8 \
    -v warnthold=0.7 \
    -v loadavg=$(getloadavg5) \
    -v numcpus=$(getnumcpus) \
    'BEGIN {
      ratio=loadavg/numcpus
      if (ratio &gt;= failthold) exit 2
      if (ratio &gt;= warnthold) exit 1
      exit 0
    }'
  </code></pre>