R.L. Dane :Debian: :OpenBSD: 🍵 :MiraLovesYou:<p>In the helpful shell functions department:</p><p>(Requires <code>bc</code> to be installed)</p><pre><code>load() {
local load=$(uptime |sed -E "s/^.*load averages?: //; s/,.*$//")
local uname="$(uname)"
local cpus
if [[ $1 == -q ]]; then
echo "$load"
elif [[ $1 == -i ]]; then
echo "$load + 0.5" |bc -l |cut -f1 -d.
else
case "$uname" in
Linux) cpus=$(grep -c ^processor /proc/cpuinfo);;
*BSD) cpus=$(sysctl hw.ncpu |tr -dc "0-9\n");;
*) warn "load(): assuming 1 cpu, don't know how to get the number in \"$uname\""
cpus=1;;
esac
local loadPerCPU=$(echo "scale=3; $load / $cpus" |bc -l |sed 's/^\./0./')
echo "$load ($loadPerCPU per processor ($cpus))"
fi
}
</code></pre><p><a href="https://polymaths.social/tags/shellscripting" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>ShellScripting</span></a> <a href="https://polymaths.social/tags/unixshell" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>UnixShell</span></a> <a href="https://polymaths.social/tags/shellscripts" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>ShellScripts</span></a> <a href="https://polymaths.social/tags/bash" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>bash</span></a> <a href="https://polymaths.social/tags/ksh" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>ksh</span></a> <a href="https://polymaths.social/tags/sh" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>sh</span></a></p>