Bash script to send notifications when low on ram Backstory

Recently, we've changed the PCs at my workplace to un Linux Mint.
It works amazing, is blazing fast and the adjustment time was very short.

However, I noticed my PC would freeze completely, sometimes.
I've determined that it is low RAM memory.

My working habits require me to open 10+ tabs (sometimes 100, in 5-8 Google Chrome windows).
This makes it so the swap is stuffed, as well as the RAM (Physical Memory).
Sometimes I have to use a VM running off of my PC, which takes 4GB for itself.

The code

Since old habits are hard to kill and isn't fun, I've decided to write code (which is a lot more fun).

Since Linux Mint doesn't warn about low available RAM, I've scattered around and put together a script to run every minute, and warn me when the memory is running low.

This script can also be executed from the console, displaying a message on it, if needed.
A detection method had to be added, since the output sent to cron is emailed by default.

#!/usr/bin/env bash
# based from https://askubuntu.com/questions/234292/warning-when-available-ram-approaches-zero
LANG=en_US.UTF-8

# gets available and total ram
RAM=$(free -m)
total=$(echo "$RAM"|awk '/^[mM]em\.?:/{print $2}')
available=$(echo "$RAM"|awk '/^[mM]em\.?:/{print $7}')

# warn if less than these levels is free
# warning = 20%
# critical = 10%
WARNING=$(expr $total / 5)
CRITICAL=$(expr $total / 10)

# -h int:transient:1 &lt;-- don't store the notification
# https://unix.stackexchange.com/questions/393397/get-notify-send-to-clear-itself-from-notification-tray/401587
if [ $available -lt $CRITICAL ]; then
    # using -u critical doesn't allow the notification to go away after -t ms have past
    # this causes issues if afk, since the notifications will queue until the -u critical is closed
    notify-send -i error -h int:transient:1 -t 60000 "Low memory!" "$available/$total MB free, critical at $CRITICAL MB"
elif [ $available -lt $WARNING ]; then
    notify-send -h int:transient:1 -t 15000 "Memory is going low" "Available: $available/$total MB, warns at $WARNING MB"
fi

# outputs if not ran by cron
# https://unix.stackexchange.com/questions/46789/check-if-script-is-started-by-cron-rather-than-invoked-manually
if [ -t 0 ]; then
    echo "Available: $available/$total MB, warns at $WARNING MB, critical at $CRITICAL MB"
fi


This script runs in crontab -e, with the following:

# https://unix.stackexchange.com/questions/247860/notify-send-doesnt-work-at-cinnamon
DISPLAY=":0.0"
XAUTHORITY="/home/&lt;username&gt;/.Xauthority"
XDG_RUNTIME_DIR="/run/user/&lt;output from id -u&gt;"

* * * * * /usr/bin/env bash /home/&lt;username&gt;/&lt;script-from-above&gt;.sh


Conclusion

It was really hard to get to this point, with plenty of issues.
Most information was available online, but, making it work was a pain.

I'm not really good with Bash scripting, which probably means that I have some really bad mistakes.
As far as I know, it works as intended, when intended:



Besides that, is there anything I can improve or change?
Any optimization/optimisation I can do?
Any localization/localisation issues that may come?
Kudos to you! This is a nice little script, easy to read and to understand. However, there is no reason to reach for expr. Most shells (including dash or even busybox sh) can interpret arithmetic expressions on their own:

WARNING=$(($total / 5))
CRITICAL=$(($total / 10))


Also, in [ ] expressions, I'd use quotes around variables, to make sure that they don't contain any spaces. In this case, we can be sure that they won't contain some, but it's still good practice to use them:

if [ "$available" -lt "$CRITICAL" ]; then
    ...
elif [ "$available" -lt "$WARNING" ]; then
    ...
fi


Other than that, I'd write the -u comment as a direct negative instead of a positive:

# Don't use `-u critical', as it will keep the notification even after -t ms
# and will cause notifications to queue up.


This comment still contains the same message: "don't use -u critical", but it's much more direct.

Since no bashism are used, we can even change the shebang to #!/bin/sh. By the way, some of those remarks were also found by ShellCheck, but it rightfully marks them as info level only.