Skip to content

Instantly share code, notes, and snippets.

@AlessioGiambrone
Last active April 1, 2017 09:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save AlessioGiambrone/52ec0f83b7d540005943442bef57ae6b to your computer and use it in GitHub Desktop.
Save AlessioGiambrone/52ec0f83b7d540005943442bef57ae6b to your computer and use it in GitHub Desktop.
#!/bin/bash
# This scripts pops up a notification in X if your RAM is occupied more
# than a certain value (default: 90%).
# Memory is checked every 3 seconds, alerts pops up every 30 seconds.
checkmemory () {
while
sleep 3
TOTAL=`free -tw | grep Mem | tr -s ' ' | cut -d ' ' -f 2`
USED=`free -tw | grep Mem | tr -s ' ' | cut -d ' ' -f 3`
PERC=`echo 100* $USED / $TOTAL | bc`
(( $PERC < $MAX ))
do :; done
BADPROCESS=`ps aux --sort -rss | head -2 | tail -1 | tr -s ' ' | rev | cut -d ' ' -f 1 | rev`
xmessage "MEMORY ALERT - $PERC% occupied, mostly by $BADPROCESS" -center
}
if [ -v $1 ]
then
MAX=90
else
MAX=$1
fi
while
checkmemory
sleep 30
do :; done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment