PowerShell/Scripts/swap2ram
2021-01-27 13:14:20 +01:00

27 lines
745 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 --human --si | awk '/Swap:/ {print $3}')
RAMsize=$(LC_ALL=C free --human --si | awk '/Mem:/ {print $2}')
RAMused=$(LC_ALL=C free --human --si | awk '/Mem:/ {print $3}')
RAMfree=$(LC_ALL=C free --human --si | awk '/Mem:/ {print $4}')
printf "Swapping $SwapUsed back to RAM ($RAMsize total, $RAMused used, $RAMfree free) ... "
start=`date +%s`
swapoff -a && swapon -a
end=`date +%s`
echo "DONE (`expr $end - $start` sec.)"
exit 0