1833772 Members
2317 Online
110063 Solutions
New Discussion

Scripting help needed

 
Amit Manna_6
Regular Advisor

Scripting help needed

Hi,
In a directory i have the following files. Is there any way which will give me only the vg names out of this. I want to write a script in which i need to put the command so that and export the VGs from the server.


vg_p01_ss01.bcv1.imp.ksh
vg_p01_ss01.imp.ksh
vg_p01_ss02.bcv1.imp.ksh
vg_p01_ss02.imp.ksh
vg_p01_ss03.bcv1.imp.ksh
vg_p01_ss03.imp.ksh
vg_p01_ss04.bcv1.imp.ksh
vg_p01_ss04.imp.ksh
vg_p01_ss05.bcv1.imp.ksh
vg_p01_ss05.imp.ksh
vg_p01_ss06.bcv1.imp.ksh
vg_p01_ss06.imp.ksh
vg_p02_ss01.bcv1.imp.ksh
vg_p02_ss01.imp.ksh
vg_p02_ss02.bcv1.imp.ksh
vg_p02_ss02.imp.ksh
vg_p02_ss03.bcv1.imp.ksh
vg_p02_ss03.imp.ksh
vg_p02_ss04.bcv1.imp.ksh
vg_p02_ss04.imp.ksh
vg_p02_ss05.bcv1.imp.ksh
vg_p02_ss05.imp.ksh
vg_p03_ss01.bcv1.imp.ksh
vg_p03_ss01.imp.ksh
vg_p03_ss02.bcv1.imp.ksh
vg_p03_ss02.imp.ksh
vg_p03_ss03.bcv1.imp.ksh
vg_p03_ss03.imp.ksh
vg_p03_ss04.bcv1.imp.ksh
vg_p03_ss04.imp.ksh
vg_p03_ss05.bcv1.imp.ksh
vg_p03_ss05.imp.ksh
vg_p04_ss01.bcv1.imp.ksh
vg_p04_ss01.imp.ksh
vg_p04_ss02.bcv1.imp.ksh
vg_p04_ss02.imp.ksh
vg_p04_ss03.bcv1.imp.ksh
vg_p04_ss04.bcv1.imp.ksh
vg_p04_ss05.bcv1.imp.ksh
vg_p05_ss01.bcv1.imp.ksh
vg_p05_ss01.imp.ksh
vg_p05_ss02.bcv1.imp.ksh
vg_p05_ss03.bcv1.imp.ksh
vg_p06_ss01.bcv1.imp.ksh
vgp_sam_a2.imp.ksh



Any Suggestion welcome.

12 REPLIES 12
James R. Ferguson
Acclaimed Contributor

Re: Scripting help needed

Hi Amit:

I am going to assume that the volume group name ends at the dot character. Hence, I assume that a valid name is "vg_p01_ss01" for example. Then:

# perl -nle 'print $1 if /(vg.*?)\./' file | uniq

...will produce a list of unique names.

You can also do:

# ls | perl -nle 'print $1 if /(vg.*?)\./' | uniq

...to pass your list of files from a directory list output directly.

Regards!

...JRF...
Jonathan Fife
Honored Contributor

Re: Scripting help needed

Something like:

for file in $(ls);
do echo ${file%%.*};done | sort -u

Is that what you're looking for? If you want the duplicates remove the | sort -u.
Decay is inherent in all compounded things. Strive on with diligence
Sandman!
Honored Contributor

Re: Scripting help needed

# awk -F. '{print $1 | "uniq"}' inp | xargs -n1 vgexport
Hein van den Heuvel
Honored Contributor

Re: Scripting help needed


Amit,
Here is a perl one-liner to get the names:

perl -ne s/\..*$//; print unless $seen{$_}++ tmp.txt

-n : loop throug input, Not printing each $_
-e : program text follows

s/\..*$//; : Find text from first dot to end and Substitue with nothing.

$seen{$_}++ : auto increment associative array element with key "$_" = vg name.
The first increment the value is still false
Any further increment it true = none zero


I think this, as well as the other suggestions solve the immediate question.

However, you should consider NOT using the intermediate file. As any of those suggestions generate a uniq name, just construct the full command and make them do the real tasks right there.

Regards,
Hein
Amit Manna_6
Regular Advisor

Re: Scripting help needed

All,
Thanks for all thes inputs. I will check these Monday and accordingly assign points -:)
perumal_2
Frequent Advisor

Re: Scripting help needed

Hi
Go to directory where you have the files and execute the following coomand to fulfill your requirements, you can can any optional arguements to the vgexport
ls -ltr | awk '{print $9}'|cut -d . -f 1 | uniq |xargs vgexport


Happy Scripting

TQ
Perumal

Amit Manna_6
Regular Advisor

Re: Scripting help needed

HI,
I tried ls -ltr | awk '{print $9}'|cut -d . -f 1 | uniq |


I am getting this

vg_p01_ss05
vg_p02_ss01
vg_p02_ss02
vg_p02_ss03
vg_p02_ss04
vg_p02_ss05
vg_p03_ss01
vg_p03_ss02
vg_p03_ss03
vg_p03_ss04
vg_p03_ss05
vg_p01_ss05
vg_p01_ss01
vg_p01_ss02
vg_p01_ss03
vg_p01_ss04
vg_p04_ss01
vg_p05_ss01
vg_p04_ss02
vgp_sam_a2
vg_p03_ss03
vg_p03_ss04
vg_p01_ss06
xpinfo
vg_p04_ss03
vg_p05_ss03
vg_p04_ss05
vg_p04_ss04
vg_p03_ss04
vg_p05_ss02
vg_p03_ss03
vg_p04_ss02
vg_p05_ss01
vg_p03_ss03
vg_p03_ss04
vg_p03_ss05
vg_p05_ss01
vg_p03_ss05
vg_p03_ss04
vg_p05_ss01
vg_p04_ss03
vg_p04_ss04
vg_p05_ss03
vg_p03_ss04
vg_p03_ss05
vg_p04_ss02
mapfile
vg_p03_ss05
vg_p05_ss02
vg_p04_ss05
vg_p05_ss03
vg_p04_ss03
vg_p03_ss03
vg_p04_ss04
vg_p03_ss05
vg_p01_ss05
vg_p02_ss01
vg_p02_ss04
vg_p02_ss02
vg_p03_ss01
vg_p03_ss02
vg_p02_ss03
vg_p02_ss05
vg_p05_ss01
vg_p06_ss01
vg_p01_ss01
vg_p01_ss02
vg_p01_ss03
vg_p01_ss04
vg_p04_ss01
vg_p01_ss06
vg_p06_ss01
vg_p05_ss02
vg_p04_ss04
vg_p04_ss05
vg_p04_ss03
vg_p05_ss02
vg_p05_ss03
vg_p04_ss05
vg_p05_ss03
vg_p04_ss03
vg_p02_ss01
vg_p03_ss05
vg_p02_ss04
vg_p03_ss05
vg_p01_ss04
vg_p03_ss05
vg_p03_ss03
vg_p01_ss05
vg_p01_ss04
vg_p01_ss05
vg_p02_ss04
vg_p03_ss04
vg_p02_ss04
vg_p03_ss04
vg_p01_ss03
vg_p01_ss02
vg_p01_ss03
vg_p03_ss01
vg_p02_ss05
vg_p02_ss02
vg_p01_ss01
vg_p01_ss02
vg_p02_ss03
vg_p02_ss02
vg_p03_ss01
vg_p02_ss05
vg_p01_ss01
vg_p04_ss01
vg_p01_ss06
vg_p05_ss01
vg_p03_ss02
vg_p05_ss01
vg_p04_ss02


Also i tried this for file in $(ls);
> do echo ${file%%.*};done | sort -u



I am getting same result. The bcv part from the VG is missing. What is the way to get that/


Please help me out. I have to do it today.
Raj D.
Honored Contributor

Re: Scripting help needed

# cut -d . -f 1 file_nm | uniq | xargs -n 1 command


" If u think u can , If u think u cannot , - You are always Right . "
Raj D.
Honored Contributor

Re: Scripting help needed

# cut -d . -f 1 file_nm | uniq | xargs -n 1 vgexport #Enjoy.
" If u think u can , If u think u cannot , - You are always Right . "
Hein van den Heuvel
Honored Contributor

Re: Scripting help needed

>> Any Suggestion welcome.

Ok:
1- If you are not comfortable scripting, or adapting the suggested solutions, then just take the closest solution and go into an editor and do the thing alright! You could have been done by now.
But scripting is preferable, even if it is more work, because it will get it right, and it will be repeatable.

2- If you want us to help better, then PLEASE be more explicit on what you want.
Input: blah.xxx.blahblah
Output: command blah.xxx yyy xxx ?
Conditions?

3-Google! +bcv +vg +import

http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=349968

4- MAN PAGE: vgchid

5 - Uniq only compares ADJACENT lines. So you must pre-sort the file or know for sure it is (still) sorted after the transformations.

6- Try this

ls | -ne s/(bcv\d+)\..*$/$1/; print unless $seen{$_}++"

Hope this helps,
Hein.
Hein van den Heuvel
Honored Contributor

Re: Scripting help needed

Oh, forgot to ask... does that setup really have dozens of volume groups? Each perhaps based on a single Physical Volume?

Please review the notion of Volume GROUPS.

The system perform better, and be easier to manage if it is set up with multiple PV's in fewer VG's carved out to multiple LV's each.

Regards,
Hein van den Heuvel
HvdH Peformance Consulting
James R. Ferguson
Acclaimed Contributor

Re: Scripting help needed

Hi (again):

It would have be easier, had you defined what constituted a volume group name in the beginning. That said, your data suggests that this will work:

# perl -nle 'print $1 if /(vg.+\.bcv\d)\..*/' file

(or):

# ls /path | perl -nle 'print $1 if /(vg.+\.bcv\d)\..*/'

Now, if you want to perform this extraction and 'vgexport' the volume groups, you could do:

# ls path | perl -nle 'print $1 if /(vg.+\.bcv\d)\..*/' | xargs -n 1 -i vgchange -a n {}

This inactivates the volume groups before their export. Then, follow with:

# ls path | perl -nle 'print $1 if /(vg.+\.bcv\d)\..*/' | xargs -n 1 -i vgexport -v -s -m {}.mapfile {}

This performs the actual 'vgexport' *and* keeps a mapfile of the volume group for reuse.

Regards!

...JRF...