2020-07-16 17:39:24 +02:00
|
|
|
#!/bin/sh
|
|
|
|
|
2020-10-23 10:05:31 +02:00
|
|
|
# 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
|
|
|
|
|
2021-01-27 09:54:09 +01:00
|
|
|
if ! [ $(id -u) = 0 ]; then
|
|
|
|
echo "Please run this script as root"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2020-10-23 10:05:31 +02:00
|
|
|
SwapUsed=$(LC_ALL=C free | awk '/Swap:/ {print $3}')
|
2020-10-09 19:13:14 +02:00
|
|
|
RAMsize=$(LC_ALL=C free | awk '/Mem:/ {print $2}')
|
|
|
|
RAMfree=$(LC_ALL=C free | awk '/Mem:/ {print $4}')
|
2020-10-23 10:03:03 +02:00
|
|
|
|
2021-01-27 09:54:09 +01:00
|
|
|
printf "Swapping $SwapUsed bytes back to RAM ($RAMfree bytes free of $RAMsize bytes total) ... "
|
2020-10-23 10:03:03 +02:00
|
|
|
start=`date +%s`
|
2020-07-16 17:39:24 +02:00
|
|
|
swapoff -a && swapon -a
|
2020-10-23 10:03:03 +02:00
|
|
|
end=`date +%s`
|
2020-10-09 19:13:14 +02:00
|
|
|
|
2021-01-27 09:54:09 +01:00
|
|
|
echo "DONE (`expr $end - $start` sec.)"
|
2020-07-16 17:39:24 +02:00
|
|
|
exit 0
|