-
Notifications
You must be signed in to change notification settings - Fork 5
/
30-diskspace
58 lines (47 loc) · 1.69 KB
/
30-diskspace
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
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/bin/bash
# This script displays the usage of specified disks
# Base version used for this script: https://github.com/Heholord/FalconStats/blob/master/scripts/discspace.sh
clear="\e[39\e[0m"
dim="\e[2m"
# The parameter maxDiskUsage indicates when the bar should be displayed as red
maxDiskUsage=80
# The parameter barWidth indicates how long the disk usage bar should be
barWidth=50
# mountpoints contains all the directories which devices should be monitored
# Examples: mountpoints="/ /boot /home" - this will monitor the devices mounted
mountpoints="/"
# Make space above
echo ""
echo "disk usage:"
for point in ${mountpoints}; do
# Get the output of df and add spaces after the newlines
# If you only want local partitions, you can add the -l flag to the df command
line=$(df -h "${point}" | sed -e ':a;N;$!ba;s/\n/\n /g')
usagePercent=$(echo "$line" | tail -n1 | awk '{print $5;}' | sed 's/%//')
usedBarWidth=$(((usagePercent * barWidth) / 100))
barContent=""
color="\e[32m"
# Color the bar red in case it's bigger than the speicified value
if [ "${usagePercent}" -ge "${maxDiskUsage}" ]; then
color="\e[31m"
fi
barContent="${color}"
# Build the usage bar
for _ in $(seq 1 $usedBarWidth); do
barContent="${barContent}="
done
# Rest of the unused space in white
barContent="${barContent}${clear}${dim}"
for _ in $(seq 1 $((barWidth - usedBarWidth))); do
barContent="${barContent}="
done
bar="[${barContent}${clear}]"
# Print the column/title bar
if [ "${titeled}" == "" ]; then
echo " ${line}"
titeled="1"
else
echo " ${line}"|tail -n1
fi
echo -e " ${bar}"
done