From 0584914cc2eb83a7e9dcfa66e69d41113aa153ea Mon Sep 17 00:00:00 2001 From: Alice Gaudon Date: Sat, 15 Feb 2020 10:13:24 +0100 Subject: [PATCH] motd.sh: add ZFS features --- motd.sh | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/motd.sh b/motd.sh index d12c731..3ffc89c 100755 --- a/motd.sh +++ b/motd.sh @@ -66,10 +66,18 @@ dim="\e[2m" undim="\e[0m" # disk usage: ignore zfs, squashfs & tmpfs -mapfile -t dfs < <(df -H -x squashfs -x tmpfs -x devtmpfs --output=target,pcent,size | tail -n+2) +DISKS=$(df -H -x squashfs -x tmpfs -x devtmpfs -x zfs --output=target,pcent,size | tail -n+2) + +if test $(command -v zpool); then + DISKS+="\n" + DISKS+=$(zpool list -o name,capacity,size | tail -n+2) +fi printf "\nDisk usage:\n" -for line in "${dfs[@]}"; do +while read line; do + if [ -z "$line" ]; then + continuetest + fi # get disk usage usage=$(echo "$line" | awk '{print $2}' | sed 's/%//') used_width=$((($usage*$bar_width)/100)) @@ -93,7 +101,7 @@ for line in "${dfs[@]}"; do # print usage line & bar echo "${line}" | awk '{ printf("%-31s%+3s used out of %+4s\n", $1, $2, $3); }' | sed -e 's/^/ /' echo -e "${bar}" | sed -e 's/^/ /' -done +done <<< $(echo -e "$DISKS") ### Welcome message ### @@ -101,3 +109,16 @@ LAST_LOGIN=$(last -w | grep arisu | 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) + while read line; do + name=$(echo "$line" | awk '{print $1}') + avail=$(echo "$line" | awk '{print $2}') + + if [ $avail -le 150000000000 ]; then + echo -e "${red}Warning! ${white}$name ${undim}has less than 150GB" + fi + done <<< $(echo -e "$POOLS") +fi \ No newline at end of file