基于df -h命令实现

[root@logstash ~]# df -h
Filesystem               Size  Used Avail Use% Mounted on
devtmpfs                 2.0G     0  2.0G   0% /dev
tmpfs                    2.0G     0  2.0G   0% /dev/shm
tmpfs                    2.0G   12M  2.0G   1% /run
tmpfs                    2.0G     0  2.0G   0% /sys/fs/cgroup
/dev/mapper/centos-root   50G  5.4G   45G  11% /
/dev/sr0                 4.4G  4.4G     0 100% /mnt
/dev/sda1               1014M  138M  877M  14% /boot
/dev/mapper/centos-home   26G   33M   26G   1% /home
tmpfs                    394M     0  394M   0% /run/user/0
[root@logstash ~]#

server_source_disk.sh

#!/bin/bash

function disk()
{
  fs=$(df -h | awk '/^\/dev/{print $1}')
  for p in $fs
  do
    mounted=$(df -h | awk '$1=="'$p'"{print $NF}')
    size=$(df -h | awk '$1=="'$p'"{print $2}')
    used=$(df -h | awk '$1=="'$p'"{print $3}')
    used_percent=$(df -h | awk '$1=="'$p'"{print $5}')
    echo "硬盘 - 挂载点:$mounted,总大小:$size,使用:$used,使用率:$used_percent"
  done
}
disk

验证:

[root@logstash ~]# sh server_source_disk.sh 
硬盘 - 挂载点:/,总大小:50G,使用:5.4G,使用率:11%
硬盘 - 挂载点:/mnt,总大小:4.4G,使用:4.4G,使用率:100%
硬盘 - 挂载点:/boot,总大小:1014M,使用:138M,使用率:14%
硬盘 - 挂载点:/home,总大小:26G,使用:33M,使用率:1%
[root@logstash ~]#