Test if swap is present

Signed-off-by: Alban Vidal <alban.vidal@zordhak.fr>
This commit is contained in:
Alban Vidal 2018-05-30 08:24:00 +02:00
parent cd2a8d7ed8
commit 3c71fa06fb

View File

@ -16,10 +16,16 @@ swapiness=`sysctl vm.swappiness |awk '{print $3}'`
memory_usage=$(free -m| grep 'Mem' |awk ' {total=$2} {avalaible=$7} END { printf("%3.1f%%", 100-avalaible/total*100)}' |awk -v red="$(tput setaf 1)" -v yellow="$(tput setaf 3)" -v green="$(tput setaf 2)" -v reset="$(tput sgr0)" '{printf "%s%s%s\n", (+$1>'$swapiness'?red:(+$1>'$mi_swapiness')?yellow:green), $1, reset}')
# SWAP
if [ $(grep SwapTotal /proc/meminfo |awk '{print $2}') -gt 0 ] ; then
# if swap exist
swap_usage=`free -m | awk '/Swap/ { printf("%3.1f%%", $3/$2*100) }'`
var4=${swap_usage%.*}
((var4 >= 1 )) && swap_usage="\033[31m$swap_usage\033[00m" || swap_usage="\033[32m$swap_usage\033[00m"
else
# if swap is absent
swap_usage="NO SWAP"
fi
# USERS AND OTHERS