mirror of
https://github.com/fleschutz/PowerShell.git
synced 2024-12-25 16:18:55 +01:00
27 lines
754 B
Bash
Executable File
27 lines
754 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 this script 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
|