PowerShell/Scripts/swap2ram
2021-01-27 09:54:09 +01:00

26 lines
649 B
Bash
Executable File

#!/bin/sh
# Syntax: ./swap2ram
# Description: swaps back to RAM
# Author: Markus Fleschutz
# Source: github.com/fleschutz/PowerShell
# License: CC0
# NOTE: for automation copy me to /etc/cron.daily
if ! [ $(id -u) = 0 ]; then
echo "Please run this script as root"
exit 1
fi
SwapUsed=$(LC_ALL=C free | awk '/Swap:/ {print $3}')
RAMsize=$(LC_ALL=C free | awk '/Mem:/ {print $2}')
RAMfree=$(LC_ALL=C free | awk '/Mem:/ {print $4}')
printf "Swapping $SwapUsed bytes back to RAM ($RAMfree bytes free of $RAMsize bytes total) ... "
start=`date +%s`
swapoff -a && swapon -a
end=`date +%s`
echo "DONE (`expr $end - $start` sec.)"
exit 0