Created
May 2, 2017 03:07
-
-
Save NullBhikkhu/3d27e64243d68a9d05a7f9a8cbb68b29 to your computer and use it in GitHub Desktop.
Transfer swapped data back to RAM
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
#!/usr/bin/env bash | |
################### | |
mem=$(LC_ALL=C free | awk '/Mem:/ {print $4}') | |
swap=$(LC_ALL=C free | awk '/Swap:/ {print $3}') | |
if [ "$EUID" -ne 0 ]; then | |
echo "ERROR: Not running as root. Nothing done." >&2 | |
exit 1 | |
fi | |
if [ $mem -lt $swap ]; then | |
echo "ERROR: Not enough RAM to write swap back. Nothing done." >&2 | |
exit 2 | |
fi | |
echo -e "Moving swapped data to RAM\033[5m...\033[0m" | |
swapoff -a && | |
swapon -a | |
echo "Done." | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment