Skip to content

Instantly share code, notes, and snippets.

@NullBhikkhu
Created May 2, 2017 03:07
Show Gist options
  • Save NullBhikkhu/3d27e64243d68a9d05a7f9a8cbb68b29 to your computer and use it in GitHub Desktop.
Save NullBhikkhu/3d27e64243d68a9d05a7f9a8cbb68b29 to your computer and use it in GitHub Desktop.
Transfer swapped data back to RAM
#!/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