motd.sh: add ZFS features

This commit is contained in:
Alice Gaudon 2020-02-15 10:13:24 +01:00
parent ad7be843cc
commit 0584914cc2
1 changed files with 24 additions and 3 deletions

27
motd.sh
View File

@ -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