update-motd.d/30-disks aktualisiert

This commit is contained in:
Kai Waggeling 2025-07-04 22:20:54 +00:00
parent d44740902e
commit dd67ef13cf

View file

@ -1,41 +1,29 @@
#!/bin/bash #!/bin/bash
# config CR='\033[0;31m'
max_usage=90 CYW='\033[1;33m'
bar_width=50 CG='\033[0;32m'
# colors CB="\e[1;34m"
white="\e[39m" NC='\033[0m' # No Color
green="\e[1;32m"
red="\e[1;31m"
dim="\e[2m"
undim="\e[0m"
# disk usage: ignore zfs, squashfs & tmpfs # Titel
mapfile -t dfs < <(df -H -x zfs -x squashfs -x tmpfs -x devtmpfs -x overlay --output=target,pcent,size | tail -n+2) echo -e "
printf "\ndisk usage:\n" echo -e "${CB}disk usage:${NC}"
echo -e ""
echo -e " Filesystem Size Used"
for line in "${dfs[@]}"; do df -h --output=source,size,pcent,target | tail -n +2 | \
# get disk usage grep -Ev 'tmpfs|devtmpfs|udev|squashfs|overlay|nfs|cifs|smbfs|fuse|proc|sysfs' | \
usage=$(echo "$line" | awk '{print $2}' | sed 's/%//') while read -r fs size pcent target; do
used_width=$((($usage*$bar_width)/100)) usage=${pcent%\%}
# color is green if usage < max_usage, else red
if [ "${usage}" -ge "${max_usage}" ]; then if [ "$usage" -ge 90 ]; then
color=$red color=$CR
else elif [ "$usage" -ge 70 ]; then
color=$green color=$CY
fi else
# print green/red bar until used_width color=$CG
bar="[${color}" fi
for ((i=0; i<$used_width; i++)); do
bar+="=" printf " %-46s %6s ${color}%4s${NC}\n" "$target" "$size" "$pcent"
done
# print dimmmed bar until end
bar+="${white}${dim}"
for ((i=$used_width; i<$bar_width; i++)); do
bar+="="
done
bar+="${undim}]"
# 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