-
Notifications
You must be signed in to change notification settings - Fork 107
/
30-zpool-bar
executable file
·45 lines (41 loc) · 1.05 KB
/
30-zpool-bar
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/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"
# zpool status
printf "\nzpool status:\n"
zpool status -x | sed -e 's/^/ /'
# zpool usage
mapfile -t zpools < <(zpool list -Ho name,cap,size)
printf "\nzpool usage:\n"
for line in "${zpools[@]}"; do
# get zpool 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
else
color=$green
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("%-30s%+3s used out of %+5s\n", $1, $2, $3); }' | sed -e 's/^/ /'
echo -e "${bar}" | sed -e 's/^/ /'
done