-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy path30-hdd-free
executable file
·34 lines (32 loc) · 998 Bytes
/
30-hdd-free
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
#!/bin/bash
mountpoints=('/dev/sdf1' '/dev/vg1/downloads' '/dev/sdb1')
barWidth=34
maxDiscUsage=90
clear="\e[39m\e[0m"
dim="\e[2m"
barclear=""
echo
echo 'HDD free:'
for point in "${mountpoints[@]}"; do
line=$(df -hl "${point}")
label=$(lsblk -o label "${point}")
usagePercent=$(echo "$line"|tail -n1|awk '{print $5;}'|sed 's/%//')
usedBarWidth=$((($usagePercent*$barWidth)/100))
barContent=""
color="\e[33m"
if [ "${usagePercent}" -ge "${maxDiscUsage}" ]; then
color="\e[31m"
fi
barContent="${color}"
for sep in $(seq 1 $usedBarWidth); do
barContent="${barContent}|"
done
barContent="${barContent}${clear}${dim}"
for sep in $(seq 1 $(($barWidth-$usedBarWidth))); do
barContent="${barContent}-"
done
bar="[${barContent}${clear}]"
echo "${label}" | awk '{if ($1 != "LABEL") printf("%-10s", $1); }'
echo "${line}" | awk '{if ($1 != "Filesystem") printf("%+8s used out of %+5s\n", $3, $2); }'
echo -e "${bar}"
done