Operating System - Linux
1826027 Members
3032 Online
109690 Solutions
New Discussion

Script - number and names of lvols

 
SOLVED
Go to solution
Piotr Kirklewski
Super Advisor

Script - number and names of lvols

Hi there

I nead to get information how many logical volumes are there in specific vg.
Til now i have this :]

strings /dev/vg00 >>myfile

group
lvol1
rlvol1
lvol2
rlvol2
lvol3
rlvol3
lvol4
rlvol4
lvol5
rlvol5
lvol6
rlvol6
lvol7
rlvol7
lvol8
rlvol8

Now I nead to remove, all rvols and group strings.
Then read every line and put strings into the variable.

What commands should I use ?

Cheers




Jesus is the King
11 REPLIES 11
Oviwan
Honored Contributor
Solution

Re: Script - number and names of lvols

hey

just grep lvol:

for lvol in $(strings /dev/vg00 | grep ^lvol) ; do

echo ${lvol} #value of current lvol

done

Regards
Peter Godron
Honored Contributor

Re: Script - number and names of lvols

Hi,
how about
vgdisplay -v /dev/vg00 | grep -e 'Cur LV' -e'LV Name'

Please also read:
http://forums1.itrc.hp.com/service/forums/helptips.do?#33 on how to reward any useful answers given to your questions.

So far you have not awarded any points !

A. Clay Stephenson
Acclaimed Contributor

Re: Script - number and names of lvols

First, strings is an extremely poor command to read a directory because depending upon the binary data in the directory, you could get all kinds of bogus strings "hits".

Simply use the ls command:

ls /dev/vg00/l* and all you are left with is "lvol1", "lvol2", ...

If you need to then process the LVOL's one at a time:

ls /dev/vg00/l* | while read LVOL
do
echo "Lvol: ${LVOL}"
done
If it ain't broke, I can fix that.
Sandman!
Honored Contributor

Re: Script - number and names of lvols

If you only want the active mounted lvols then try the pipeline below:

# bdf | (echo "number of vg00 lvols...\c";grep -c vg00)
James R. Ferguson
Acclaimed Contributor

Re: Script - number and names of lvols

Hi:

One way is:

# LV=`vgdisplay -v vg00|awk '{if (/LV Name/) {split($3,a,/\//);printf "%s ",a[4]}}'`

# echo ${LV}

Regards!

...JRF...
Piotr Kirklewski
Super Advisor

Re: Script - number and names of lvols

Oviwan
Your replay is great becase the outpoot look like:

lvol1
lvol2
...

But what in sytuation when one or mre logical volumes hae different then standard names, for example: test, mylvol or whatever?

Cheers
Jesus is the King
A. Clay Stephenson
Acclaimed Contributor

Re: Script - number and names of lvols

Okay, if you want to go out of your way to create non-standard lvol names (in that they don't begin with 'l') then:

find /dev/vg00 -type b | while read LVOL
do
echo "Lvol: ${LVOL}"
done
If it ain't broke, I can fix that.
Oviwan
Honored Contributor

Re: Script - number and names of lvols

you can extend the grep pattern like

grep -E '^lvol|group|^rlvol'

and so on

Regards
James R. Ferguson
Acclaimed Contributor

Re: Script - number and names of lvols

Hi (again):

The solution I offered also works with non-standard logical volume names. Try it.

Regards!

...JRF...
Piotr Kirklewski
Super Advisor

Re: Script - number and names of lvols

Great :)
Thank you.
Jesus is the King
Hein van den Heuvel
Honored Contributor

Re: Script - number and names of lvols

Piotr,

A 'thank you' is great and much appreciated feedback.

ut please also consider: http://forums1.itrc.hp.com/service/forums/helptips.do?#28

Be assiging appropriate points future readers will know which replies to focus on.

Also, you may want to 'close' this topic after 'submit' for points.

Cheers,
Hein van den Heuvel
[0 points for this]