通过fdisk -l计算总容量,通过df -k计算使用量;
脚本内容:
#!/bin/bash list=( 10.10.5.43 10.78.1.179 10.78.1.84 10.78.1.54 ) awk 'BEGIN{printf "%s\t%s\t%s\n","IP地址","磁盘总容量/G","磁盘总使用量/G"}' for ip in ${list[*]};do echo -n "$ip " ssh $ip fdisk -l | grep "Disk /dev/sd" | awk -F '[ :,]+' '{printf "%.0f\n",$5/1072741824}' | awk -v total=0 '{total+=$1}END{printf "%.0f\t",total}' ssh $ip df -k | grep -v "tmpfs" | egrep -A 1 "mapper|sd" | awk 'NF>1{print $(NF-3)}' | awk -v used=0 '{used+=$1}END{printf "%.2f\n",used/1048576}' done
执行脚本输出:
IP地址 磁盘总容量/G 磁盘总使用量/G 10.10.5.43 300 5.93 10.78.1.179 80 2.50 10.78.1.84 80 2.48 10.78.1.54 330 97.12
转载于:https://blog.51cto.com/liuzhengwei521/2320610