I like the script. But I have maybe some sugestionssuggestions for improvement.
RAM=$(free -m) total=$(echo "$RAM"|awk '/^[mM]em\.?:/{print $2}') available=$(echo "$RAM"|awk '/^[mM]em\.?:/{print $7}')
RAM=$(free -m) total=$(echo "$RAM"|awk '/^[mM]em\.?:/{print $2}') available=$(echo "$RAM"|awk '/^[mM]em\.?:/{print $7}')
Personaly iPersonalty I prefer to dig these values from /proc/meminfo to avoid running unnecessary free utility, but I saw serveralseveral scripts based on it. And in case that is a small script for desktop... why not :)
However. The main advantegeadvantage of the output from free -m is, that all information you need contains just one line. Try to hold the adventageadvantage. Multiple lines with awk usage isn't necessary here.
Try this:
read -r _ total _ _ _ _ available <<< $(free -m | grep -i mem)
read -r _ total _ _ _ _ available <<< $(free -m | grep -i mem)
Second thing is aritmetic,arithmetic: as @Zeta mentioned in previouseprevious answer, there ins'tisn't a reason for using expr. But instead:
WARNING=$(($total / 5)) CRITICAL=$(($total / 10))
WARNING=$(($total / 5)) CRITICAL=$(($total / 10))
warning=$(( total / 2 )) critical=$(( total / 10 ))
warning=$(( total / 2 ))
critical=$(( total / 10 ))
The rest could be okokay. But you are forcing bash that to dotest condition about warningwarning and criticalcritical, and in case thatwhen the script wasn't run by cron, you don't use it? PittyPity.