Last active
May 27, 2018 13:53
-
-
Save yuwash/6648f953a5c8e3f1dd83c453ed2f5ebc to your computer and use it in GitHub Desktop.
Warn on nearly full memory
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# see https://askubuntu.com/questions/276234/need-application-script-alerting-when-system-memory-is-running-out/346779#346779 | |
# add crontab -e the following: | |
# * * * * * DISPLAY=:0.0 /path/to/memwarn.bash | |
#Minimum available memory limit, MB | |
if [[ -n "$1" ]]; then | |
THRESHOLD="$1" | |
else | |
THRESHOLD=400 | |
fi | |
free_output="$(free -m)" | |
free_free () { | |
awk '/^Mem:/{print $4}' | |
} | |
free_buffers_cache () { | |
awk '/^Mem:/{print $6}' | |
} | |
free_available () { | |
awk '/^Mem:/{print $7}' | |
} | |
free_="$(free_free <<< "$free_output")" | |
buffcache="$(free_buffers_cache <<< "$free_output")" | |
available="$((free_ + buffcache))" | |
message="$free_output" | |
if [[ $available -lt $THRESHOLD ]]; then | |
notify-send "Memory is running out!" "$message" | |
paplay /usr/share/sounds/freedesktop/stereo/alarm-clock-elapsed.oga | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment