Small script to get LUN id from powermt output when supplied with a list of disks. It’s a tedious job to extract LUN id from the output when you have a list of disks to wok upon.
Requirement :
You have a list of disk names from OS end and you need to get their respective LUN ids from powermt
output.
This requires manual work of searching each disk name in output and then copying its respective LUN id. Typically these three lines you are interested in powermt
output.
Pseudo name=emcpoweraa
Symmetrix ID=000549754319
Logical device ID=03C4
If you have a list of disks to search its a tedious task. Because you have to search each and every disk name in the output.
Solution :
Get the output of powermt
command in a file
# powermt display dev=all > powermt.old
Get all disk names in one file e.g. test.txt
Run a for loop which will get LUN id of each disk described in the file. In this loop, we are taking each disk and searching it in the above file. Then we are extracting 2 below lines from disk name (since 2nd line below disk name contains LUN id). And then extracting LUN id from it with some data filtering.
# for i in `cat test`
do
cat powermt.old |grep -A 2 $i|grep Logical|awk '{print $3}'|cut -d= -f2
done
You will be presented with the list of LUN ids for respective disks in the test.txt
file! You can even echo disk name before LUN id by inserting echo $i
just above cat command in the above code.
Vice versa:
Get disk names by giving LUN ids in text.txt file. Its same logic, the only difference is we will be extracting above 2 lines rather than below ones. Rest all procedure remains the same.
# for i in `cat test`
do
cat powermt.old |grep -B 2 $i|grep Pseudo|awk '{print $2}'|cut -d= -f2
done