Skip to content

Instantly share code, notes, and snippets.

@anirudh-ramesh
Forked from AlessioGiambrone/checkmemory.sh
Created March 18, 2017 14:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anirudh-ramesh/1c75a776d67a1027010c0358f7020ae5 to your computer and use it in GitHub Desktop.
Save anirudh-ramesh/1c75a776d67a1027010c0358f7020ae5 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 30 seconds.
checkmemory () {
while
sleep 30
FREE=`free -tw | grep Mem | tr -s ' ' | cut -d ' ' -f 4`
USED=`free -tw | grep Mem | tr -s ' ' | cut -d ' ' -f 3`
PERC=`echo 100* $USED / $FREE | 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
checkmemory
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment