I am writing the bash script which will show the disk usage status. If the size of the filesystem is used more than 95% then that line should be highlighted only one time like below. Basically, I want my script to work same as command df -h
but with highlighting maximum disk usage. And other filesystems also should be on output.
Here is my script.
readarray -t disk <<< "$(df -h | awk '{print $5}' | tail -n +2 | tr -d %)"
for i in "${disk[@]}"
do
if [ $i -gt 95 ]
then
df -h | grep --color -E "$i%|$"
fi
done
# df -h Filesystem Size Used Avail Use% Mounted on devtmpfs 3.9G 0 3.9G 0% /dev tmpfs 3.9G 140M 3.8G 4% /dev/shm tmpfs 3.9G 1.8M 3.9G 1% /run tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup /dev/mapper/centos-root 128G 107G 15G 96% / tmpfs 3.9G 15M 3.9G 1% /tmp /dev/sda1 453M 179M 247M 42% /boot tmpfs 789M 20K 789M 1% /run/user/42 tmpfs 789M 60K 789M 1% /run/user/1000 /dev/mapper/centos-home 100G 85G 16G 96% /mnt