Talvez um pouco atrasado, mas deixo aqui um roteiro que fiz:
#!/bin/bash
IFS=$'\n'
export IFS
phydis=$(pvdisplay | egrep "PV Name|VG Name|PV Size" | awk 'NR%3{printf "%s,",$0;next}{print;}' | sed 's/PV Name//g' | sed 's/VG Name//g' | sed 's/PV Size//g' | sed 's/ //g')
if [ -f /etc/redhat-release ];then
if [[ 'cat /etc/redhat-release | awk -F " " '{print$4}' | awk -F "." '{print$1}'' -eq 7 ]];then
logdis=$(lvdisplay | egrep "LV Path|LV Size" | awk 'NR%2{printf "%s,",$0;next}{print;}' | sed 's/LV Path//g' | sed 's/LV Size//g' | sed 's/ //g' | sort)
else
logdis=$(lvdisplay | egrep "LV Name|LV Size" | awk 'NR%2{printf "%s,",$0;next}{print;}' | sed 's/LV Name//g' | sed 's/LV Size//g' | sed 's/ //g' | sort)
fi
else
logdis=$(lvdisplay | egrep "LV Name|LV Size" | awk 'NR%2{printf "%s,",$0;next}{print;}' | sed 's/LV Name//g' | sed 's/LV Size//g' | sed 's/ //g' | sort)
flag="norh"
fi
phyparttrans=""
echo "|--------------------------|----------------------|----------------------|----------------------|--------------------------------|----------------------|-----------------|-----------------|--------------------------------|"
echo "| PV Name | PV Size | VG Name | VG Size | LV Name | LV Size | Used | Avail | Mounted on |"
for phy in ${phydis};do
phypart1=$(echo "${phy}" | awk -F "," '{print$1}')
phypart2=$(echo "${phy}" | awk -F "," '{print$2}')
phypart3=$(echo "${phy}" | awk -F "," '{print$3}' | cut -f1 -d"/")
if [ "$phypart2" != "$phyparttrans" ];then
phyparttrans="$phypart2"
counter=1
for log in ${logdis};do
volsize=$(vgdisplay | egrep "VG Name|VG Size" | awk 'NR%2{printf "%s,",$0;next}{print;}' | sed 's/VG Name//g' | sed 's/VG Size//g' | sed 's/ //g' | grep "$phypart2" | awk -F "," '{print$2}')
logpart1=$(echo "${log}" | awk -F "," '{print$1}')
logpart2=$(echo "${log}" | awk -F "," '{print$2}')
logpartmatch=$(echo "${logpart1}" | awk -F "/" '{print$3}')
if [ $counter -eq 1 ];then
if [ "${phypart2}" == "${logpartmatch}" ];then
mountpoint1=$(echo "$logpart1" | awk -F "/" '{print$3}')
mountpoint2=$(echo "$logpart1" | awk -F "/" '{print$4}')
df_output=$(df -h /dev/mapper/${mountpoint1}-${mountpoint2} | tail -1)
Used=$(echo "$df_output" | awk -F " " '{print$2}')
Avail=$(echo "$df_output" | awk -F " " '{print$3}')
Mounted=$(echo "$df_output" | awk -F " " '{print$NF}')
echo "|--------------------------|----------------------|----------------------|----------------------|--------------------------------|----------------------|-----------------|-----------------|--------------------------------|"
printf '%1s %-24s %1s %-20s %1s %-20s %1s %-20s %1s %-30s %1s %-20s %1s %-15s %1s %-15s %1s %-30s %1s\n' "|" "$phypart1" "|" "$phypart3" "|" "$phypart2" "|" "$volsize" "|" "$logpart1" "|" "$logpart2" "|" "$Used" "|" "$Avail" "|" "$Mounted" "|"
counter=$[$counter +1]
elif [[ "${flag}" == "norh" ]];then
df_output=$(df -h /dev/${phypart2}/${logpart1} | tail -1)
Used=$(echo "$df_output" | awk -F " " '{print$2}')
Avail=$(echo "$df_output" | awk -F " " '{print$3}')
Mounted=$(echo "$df_output" | awk -F " " '{print$NF}')
echo "|--------------------------|----------------------|----------------------|----------------------|--------------------------------|----------------------|-----------------|-----------------|--------------------------------|"
printf '%1s %-24s %1s %-20s %1s %-20s %1s %-20s %1s %-30s %1s %-20s %1s %-15s %1s %-15s %1s %-30s %1s\n' "|" "$phypart1" "|" "$phypart3" "|" "$phypart2" "|" "$volsize" "|" "$logpart1" "|" "$logpart2" "|" "$Used" "|" "$Avail" "|" "$Mounted" "|"
counter=$[$counter +1]
fi
else
if [ "${phypart2}" == "${logpartmatch}" ];then
mountpoint1=$(echo "$logpart1" | awk -F "/" '{print$3}')
mountpoint2=$(echo "$logpart1" | awk -F "/" '{print$4}')
df_output=$(df -h /dev/mapper/${mountpoint1}-${mountpoint2} | tail -1)
Used=$(echo "$df_output" | awk -F " " '{print$2}')
Avail=$(echo "$df_output" | awk -F " " '{print$3}')
Mounted=$(echo "$df_output" | awk -F " " '{print$NF}')
printf '%1s %-24s %1s %-20s %1s %-20s %1s %-20s %1s %-30s %1s %-20s %1s %-15s %1s %-15s %1s %-30s %1s\n' "|" " " "|" " " "|" " " "|" " " "|" "$logpart1" "|" "$logpart2" "|" "$Used" "|" "$Avail" "|" "$Mounted" "|"
counter=$[$counter +1]
elif [[ "${flag}" == "norh" ]];then
df_output=$(df -h /dev/${phypart2}/${logpart1} | tail -1)
Used=$(echo "$df_output" | awk -F " " '{print$2}')
Avail=$(echo "$df_output" | awk -F " " '{print$3}')
Mounted=$(echo "$df_output" | awk -F " " '{print$NF}')
printf '%1s %-24s %1s %-20s %1s %-20s %1s %-20s %1s %-30s %1s %-20s %1s %-15s %1s %-15s %1s %-30s %1s\n' "|" " " "|" " " "|" " " "|" " " "|" "$logpart1" "|" "$logpart2" "|" "$Used" "|" "$Avail" "|" "$Mounted" "|"
counter=$[$counter +1]
fi
fi
done
else
printf '%1s %-24s %1s %-20s %1s %-20s %1s %-20s %1s %-30s %1s %-20s %1s %-15s %1s %-15s %1s %-30s %1s\n' "|" "$phypart1" "|" "$phypart3" "|" " " "|" " " "|" " " "|" " " "|" " " "|" " " "|" " " "|"
fi
done
echo "|--------------------------|----------------------|----------------------|----------------------|--------------------------------|----------------------|-----------------|-----------------|--------------------------------|"
Atualizar
Here is the script exit example:
[root@server01 /root/scripts]# ./lvm_display.sh
|--------------------------|----------------------|----------------------|----------------------|--------------------------------|----------------------|-----------------|-----------------|--------------------------------|
| PV Name | PV Size | VG Name | VG Size | LV Name | LV Size | Used | Avail | Mounted on |
|--------------------------|----------------------|----------------------|----------------------|--------------------------------|----------------------|-----------------|-----------------|--------------------------------|
| /dev/cciss/c0d2 | 1.64TB | VolGroup01 | 1.64TB | /dev/VolGroup01/backup_files | 50.00GB | 132M | 50G | /data/backup_files |
| | | | | /dev/VolGroup01/data | 1000.00GB | 591G | 410G | /data |
| | | | | /dev/VolGroup01/ftp | 100.00GB | 74G | 27G | /data/ftp |
| | | | | /dev/VolGroup01/dir1 | 50.00GB | 15G | 36G | /prod/app/dir1 |
| | | | | /dev/VolGroup01/nfs_test | 12.00GB | 127G | 224K | /dev |
| | | | | /dev/VolGroup01/testing | 200.00GB | 39G | 162G | /data/testing |
| | | | | /dev/VolGroup01/shared | 125.00GB | 15G | 111G | /data/shared |
|--------------------------|----------------------|----------------------|----------------------|--------------------------------|----------------------|-----------------|-----------------|--------------------------------|
| /dev/cciss/c0d0p2 | 558.78GB | VolGroup00 | 558.75GB | /dev/VolGroup00/LogVol00 | 10.00GB | 7.0G | 2.3G | / |
| | | | | /dev/VolGroup00/LogVol01 | 32.00GB | 127G | 224K | /dev |
| | | | | /dev/VolGroup00/LogVol02 | 120.00GB | 57G | 54G | /prod |
| | | | | /dev/VolGroup00/LogVol03 | 10.00GB | 160M | 9.1G | /tmp |
| | | | | /dev/VolGroup00/LogVol05 | 336.75GB | 205G | 133G | /data |
|--------------------------|----------------------|----------------------|----------------------|--------------------------------|----------------------|-----------------|-----------------|--------------------------------|
Qualquer melhoria é bem-vinda!