-
-
Save anirudh-ramesh/1c75a776d67a1027010c0358f7020ae5 to your computer and use it in GitHub Desktop.
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 | |
# 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