Skip to content

Instantly share code, notes, and snippets.

@UKNC
Created February 26, 2018 11:29
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 UKNC/0e7dbda2a05eeb1ba8f7c9f0ae4553db to your computer and use it in GitHub Desktop.
Save UKNC/0e7dbda2a05eeb1ba8f7c9f0ae4553db to your computer and use it in GitHub Desktop.
OOM warner script
#!/bin/bash
# Run from ~/.bashrc as
# if pgrep oom-warner > /dev/null; then
# echo oom-warner already running, exiting...
# else
# nohup ~/bin/oom-warner.sh &
# fi
#Minimum available memory limit, MB
THRESHOLD=500
#Check time interval, sec
INTERVAL=20
while :
do
free=$(free -m|awk '/^Mem:/{print $4}')
buffers=$(free -m|awk '/^Mem:/{print $6}')
available=$(free -m | awk '/^Mem:/{print $7}')
message="Free $free""MB"", buffers $buffers""MB"", available $available""MB"""
if [ $available -lt $THRESHOLD ]
then
notify-send "Memory is running out!" "$message"
fi
echo $message
sleep $INTERVAL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment