From a2981a3e35869f33e69eeec7dda99dcc1b83f237 Mon Sep 17 00:00:00 2001 From: Alice Gaudon Date: Mon, 4 Oct 2021 11:35:37 +0200 Subject: [PATCH] Update motd.sh --- motd.sh | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/motd.sh b/motd.sh index 3ffc89c..c2cd436 100755 --- a/motd.sh +++ b/motd.sh @@ -26,8 +26,8 @@ undim="\e[0m" services=($(cat /.motd.services)) # sort services -IFS=$'\n' services=($(sort <<<"${services[*]}")) -unset IFS +#IFS=$'\n' services=($(sort <<<"${services[*]}")) +#unset IFS service_status=() # get status of all services @@ -56,7 +56,7 @@ printf "$out" | column -ts $',' | sed -e 's/^/ /' ### Disk space ### # config -max_usage=90 +max_usage=80 bar_width=50 # colors white="\e[39m" @@ -105,20 +105,23 @@ done <<< $(echo -e "$DISKS") ### Welcome message ### -LAST_LOGIN=$(last -w | grep arisu | head -2 | tail -1) +LAST_LOGIN=$(last -w | grep $(whoami) | head -2 | tail -1) echo -e echo -e "Welcome to $(hostname), $(whoami)! Last login: $(echo "$LAST_LOGIN" | awk '{for(i=4;i<=NF;i++) print $i}' | paste -sd ' ') from $(echo "$LAST_LOGIN" | awk '{print $3}')" ### ZFS available space warning ### if test $(command -v zfs); then - POOLS=$(zfs list -o name,available -p | tail -n+2) + POOLS=$(zfs list -o name,used,available -p | tail -n+2) while read line; do name=$(echo "$line" | awk '{print $1}') - avail=$(echo "$line" | awk '{print $2}') + used=$(echo "$line" | awk '{print $2}') + avail=$(echo "$line" | awk '{print $3}') - if [ $avail -le 150000000000 ]; then - echo -e "${red}Warning! ${white}$name ${undim}has less than 150GB" + percentage=$(echo "scale=2;$avail/($used+$avail)*100" | bc) + + if (( $(echo "$percentage < 20" | bc -l) )); then + echo -e "${red}Warning! ${white}$name ${undim}only has ${percentage}% capacity left" fi done <<< $(echo -e "$POOLS") -fi \ No newline at end of file +fi