Added device sizes, better table layout

master
BrainwreckedTech 3 years ago
parent cdf2eba176
commit 9452a3693f

18
bdmap

@ -21,9 +21,23 @@ OUTPUT="$(echo "${OUTPUT}" | sed 's/ -> / /g')"
# SWAP COLUMNS
OUTPUT="$(echo "${OUTPUT}" | awk '{t=$1; $1=$2; $2=t; print;}')"
# NOW GET DEVICE IDs
# NOW GET DEVICE IDs and SIZES
echo "${OUTPUT}" | while read -r LOCATION BLOCKDEV; do
DEVICE_ID="$(ls -l --color=never /dev/disk/by-id | sed 's/ \+/ /g' | grep -v 'nvme-eui\|wwn-' | grep "${BLOCKDEV}$" | cut -d\ -f9)"
echo "${LOCATION} ${BLOCKDEV} ${DEVICE_ID}"
DEV_BYTES="$(lsblk -bnPo NAME,SIZE | grep "\"${BLOCKDEV}\"" | cut -d\" -f 4)"
if [ "${DEV_BYTES}" -ge $((1000**5)) ]; then
DEVICE_SZ="$((DEV_BYTES/1000**5))P"
elif [ "${DEV_BYTES}" -ge $((1000**4)) ]; then
DEVICE_SZ="$((DEV_BYTES/1000**4))T"
elif [ "${DEV_BYTES}" -ge $((1000**3)) ]; then
DEVICE_SZ="$((DEV_BYTES/1000**3))G"
elif [ "${DEV_BYTES}" -ge $((1000**2)) ]; then
DEVICE_SZ="$((DEV_BYTES/1000**2))M"
elif [ "${DEV_BYTES}" -ge 1000 ]; then
DEVICE_SZ="$((DEV_BYTES/1000))K"
else
DEVICE_SZ="${DEV_BYTES}B"
fi
printf '%-20s %-9s %4s %s\n' "${LOCATION}" "${BLOCKDEV}" "${DEVICE_SZ}" "${DEVICE_ID}"
done

Loading…
Cancel
Save