Last active
April 1, 2017 09:30
-
-
Save AlessioGiambrone/52ec0f83b7d540005943442bef57ae6b 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 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