Skip to content

Instantly share code, notes, and snippets.

@alexfornuto
Last active August 29, 2015 13:59
Show Gist options
  • Save alexfornuto/10477986 to your computer and use it in GitHub Desktop.
Save alexfornuto/10477986 to your computer and use it in GitHub Desktop.
Swapclear.sh
#!/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
@alexfornuto
Copy link
Author

Checks to see if you have more free RAM then used swap. If so it turns swap off and back on to flush it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment