Use column instead of printf for dynamic column widths

master
BrainwreckedTech 3 years ago
parent 9452a3693f
commit 67390c5816

21
bdmap

@ -1,29 +1,29 @@
#!/bin/sh #!/bin/sh
# GET THE INITITAL OUTPUT OF `ls /sys/block` # GET THE INITITAL OUTPUT OF `ls /sys/block`
OUTPUT="$(ls -l --color=never /sys/block | grep -v virtual | grep devices | cut -d\ -f9-)" BLK_INFO="$(ls -l --color=never /sys/block | grep -v virtual | grep devices | cut -d\ -f9-)"
# STRIP OFF THE PCI BUS LOCATION INFORMATION # STRIP OFF THE PCI BUS LOCATION INFORMATION
OUTPUT="$(echo "${OUTPUT}" | sed 's|\.\.\/devices/pci[0-9a-f:]\{7\}\(/[0-9a-f:.]\{12\}\)\+/||g')" BLK_INFO="$(echo "${BLK_INFO}" | sed 's|\.\.\/devices/pci[0-9a-f:]\{7\}\(/[0-9a-f:.]\{12\}\)\+/||g')"
#STRIP OFF THE SUPERFLUOUS USB HOST INFORMATION #STRIP OFF THE SUPERFLUOUS USB HOST INFORMATION
OUTPUT="$(echo "${OUTPUT}" | sed 's|\(usb[0-9]\+\)/.*/host|\1/host|g')" BLK_INFO="$(echo "${BLK_INFO}" | sed 's|\(usb[0-9]\+\)/.*/host|\1/host|g')"
# CONDENSE THE TARGET INFORMATION # CONDENSE THE TARGET INFORMATION
OUTPUT="$(echo "${OUTPUT}" | sed 's|target[0-9:]\+/[0-9:]\+:\([0-9]\+\)|target\1|g')" BLK_INFO="$(echo "${BLK_INFO}" | sed 's|target[0-9:]\+/[0-9:]\+:\([0-9]\+\)|target\1|g')"
# STRIP OFF BLOCKS # STRIP OFF BLOCKS
OUTPUT="$(echo "${OUTPUT}" | sed 's|/block/.*||g')" BLK_INFO="$(echo "${BLK_INFO}" | sed 's|/block/.*||g')"
# CONVERT -> TO A SPACE # CONVERT -> TO A SPACE
OUTPUT="$(echo "${OUTPUT}" | sed 's/ -> / /g')" BLK_INFO="$(echo "${BLK_INFO}" | sed 's/ -> / /g')"
# SWAP COLUMNS # SWAP COLUMNS
OUTPUT="$(echo "${OUTPUT}" | awk '{t=$1; $1=$2; $2=t; print;}')" BLK_INFO="$(echo "${BLK_INFO}" | awk '{t=$1; $1=$2; $2=t; print;}')"
# NOW GET DEVICE IDs and SIZES # NOW GET DEVICE IDs and SIZES
echo "${OUTPUT}" | while read -r LOCATION BLOCKDEV; do echo "${BLK_INFO}" | 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)" DEVICE_ID="$(ls -l --color=never /dev/disk/by-id | sed 's/ \+/ /g' | grep -v 'nvme-eui\|wwn-' | grep "${BLOCKDEV}$" | cut -d\ -f9)"
DEV_BYTES="$(lsblk -bnPo NAME,SIZE | grep "\"${BLOCKDEV}\"" | cut -d\" -f 4)" DEV_BYTES="$(lsblk -bnPo NAME,SIZE | grep "\"${BLOCKDEV}\"" | cut -d\" -f 4)"
if [ "${DEV_BYTES}" -ge $((1000**5)) ]; then if [ "${DEV_BYTES}" -ge $((1000**5)) ]; then
@ -39,5 +39,8 @@ echo "${OUTPUT}" | while read -r LOCATION BLOCKDEV; do
else else
DEVICE_SZ="${DEV_BYTES}B" DEVICE_SZ="${DEV_BYTES}B"
fi fi
printf '%-20s %-9s %4s %s\n' "${LOCATION}" "${BLOCKDEV}" "${DEVICE_SZ}" "${DEVICE_ID}" echo "${LOCATION} ${BLOCKDEV} ${DEVICE_SZ} ${DEVICE_ID}" >> /tmp/bdmap
done done
column -t -R3 -o" " /tmp/bdmap
rm /tmp/bdmap

Loading…
Cancel
Save