linux

linux: pretty printing multi-path device name and size

As part of an automation I had to collect only the name and size of the multi-path devices attached to a given VM. Here is the result:

multipath -ll | sed -n ‘/^mpath/,/^size/p’ >> /tmp/mpath.log && x=1 && while IFS=”” read -r p || [ -n “$p” ]; do STR1=$(printf ‘%s\n’ “$p” | sed ‘s/\s.*$//’); STR2+=$STR1″ “; y=$(($x % 2)); if [ $y -eq 0 ]; then printf ‘%s\n’ “$STR2”; echo “—“; STR2=””; fi; x=$(( $x + 1 )); done < /tmp/mpath.log; rm -f /tmp/mpath.log; touch /tmp/mpath.log;

You can also get if from here https://gist.github.com/rpsene/41ade69f9ff493b0f26c66963b3d8502

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s