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