Skip to content

Instantly share code, notes, and snippets.

@ryran
Last active December 19, 2015 15:19
Show Gist options
  • Save ryran/5975467 to your computer and use it in GitHub Desktop.
Save ryran/5975467 to your computer and use it in GitHub Desktop.
A little bash function for parsing through multipath -ll output.
#!/bin/bash
function mll {
local inputfile search_cmd
# If directory, assume sosreport and look for multipath output
if [[ -d $1 ]]; then
inputfile=$1/sos_commands/devicemapper/multipath_-v4_-ll
[[ -r $inputfile ]] || { echo -e "'$inputfile' unreadable\nRun with no args to see usage"; return 2; }
elif [[ -f $1 && -r $1 ]]; then
inputfile=$1
else
echo "Arg 1: must be file containing 'multipath -ll' output or dir-root of sosreport"
echo "Arg 2 (optional): should be a wwid, friendly name, or LUN identifier to search for"
return 1
fi
# If 1 arg only, use cat to process output
# Otherwise, search for second arg in output
[[ $# == 1 ]] && search_cmd=cat || search_cmd="awk -vRS=\n\n /$2/"
awk '
/^[[:graph:]]+ \([[:alnum:][:punct:]]+\) *dm-/
/^[[:graph:]]+ *dm-/
/^\[?size=/
/(\\_|\|-|`-)/
' "$inputfile" | sed '1!s,^[[:alnum:]].*dm-,\n&,' | $search_cmd
}
@ryran
Copy link
Author

ryran commented Jul 11, 2013

Usage example:

[rsaw:zarch]$ mll multipathfun-sosreport/ mpath11
mpath11 (123456789000000000000000000000000) dm-13 IBM,2145
[size=50G][features=1 queue_if_no_path][hwhandler=0][rw]
\_ round-robin 0 [prio=20][active]
 \_ 3:0:4:3 sds 65:32  [active][ready]
 \_ 3:0:5:3 sdw 65:96  [active][ready]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment