Last active
August 29, 2015 13:59
-
-
Save alexfornuto/10477986 to your computer and use it in GitHub Desktop.
Swapclear.sh
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 | |
meminfo=($(tr '\n' ' ' < /proc/meminfo)) | |
# MemFree Buffers Caches SwapTotal SwapFree | |
if [ $(( ${meminfo[4]} + ${meminfo[7]} + ${meminfo[10]} )) -gt $(( ${meminfo[52]} - ${meminfo[55]} )) ]; then | |
sudo swapoff -a; | |
sudo swapon -a; | |
echo "Flushed Swap" | |
else | |
echo "Nothing to do here" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Checks to see if you have more free RAM then used swap. If so it turns swap off and back on to flush it.