PowerShell/Scripts/swap2ram.sh

27 lines
757 B
Bash
Raw Normal View History

2021-09-27 10:38:12 +02:00
#!/bin/sh
2020-07-16 17:39:24 +02:00
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
2021-02-04 19:42:39 +01:00
# NOTE: for automation copy this script to /etc/cron.daily
2020-10-23 10:05:31 +02:00
2021-01-27 09:54:09 +01:00
if ! [ $(id -u) = 0 ]; then
echo "Please run this script as root"
exit 1
fi
2021-01-27 13:14:20 +01:00
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}')
2020-10-23 10:03:03 +02:00
2021-01-27 13:14:20 +01:00
printf "Swapping $SwapUsed back to RAM ($RAMsize total, $RAMused used, $RAMfree free) ... "
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