1752569 Members
4821 Online
108788 Solutions
New Discussion юеВ

Re: Script question

 
SOLVED
Go to solution
Roger Baptiste
Honored Contributor

Script question

hi,

I have two files from which i would like to build a third file-

VGfile:(sample)
VG01 001 009 010 019
VG02 109 110 1A0 1B0
....

syminq.out: (sample)
****
/dev/rdsk/c49t0d0 M(8) EMC SYMMETRIX 5567 34001000 15697920
/dev/rdsk/c54t0d0 M(8) EMC SYMMETRIX 5567 34001000 15697920
/dev/rdsk/c49t0d1 M(8) EMC SYMMETRIX 5567 34009000 15697920
/dev/rdsk/c54t0d1 M(8) EMC SYMMETRIX 5567 34009000 15697920
.....

**

Using these two files, i would like to build a file , which will have the corresponding VG appended to every entry in syminq.out file as follows:
---
/dev/rdsk/c49t0d0 M(8) EMC SYMMETRIX 5567 34001000 15697920 VG01
/dev/rdsk/c54t0d0 M(8) EMC SYMMETRIX 5567 34001000 15697920 VG01
/dev/rdsk/c54t0d1 M(8) EMC SYMMETRIX 5567 34009000 15697920 VG01
/dev/rdsk/c49t0d1 M(8) EMC SYMMETRIX 5567 34009000 15697920 VG01
----

Any elegant way to do this?

thanks

 

 

P.S. This thread has been moved from HP-UX > System Administration to HP-UX >  languages - HP Forum Moderator

Take it easy.
18 REPLIES 18
H.Merijn Brand (procura
Honored Contributor

Re: Script question

What is the joinable data?

34001000 == 001 009 010 019
Enjoy, Have FUN! H.Merijn
Sridhar Bhaskarla
Honored Contributor

Re: Script question

Raj,


1. Read syminq.out using while
2. Take out the first entry and replace rdsk with dsk.
3. Do a pvdisplay on that entry and grep for VG Name and use awk to filter out the vg.
4. Since you are still in the while loop append
vg to the line (or $0).

-Sri


PS: probably you forgot yourself that you developed a helpdesk system.
You may be disappointed if you fail, but you are doomed if you don't try
Roger Baptiste
Honored Contributor

Re: Script question

Yes, the joinable data is 34
i.e 34001 34009 etc.

In shell, grep seems the obvious way to go about it. But, once i get the grep results , how do i plug in the VG name for each entry in the last column?

Ok, over to perl procura ;-) This should be a breeze in perl.

cheers!
Take it easy.
H.Merijn Brand (procura
Honored Contributor

Re: Script question

OK, but is your sample output correct then? You put VG01 to both 34001 and 34009 lines?
Enjoy, Have FUN! H.Merijn
Sukant Naik
Trusted Contributor

Re: Script question

Hi Rajman,

Here is the script for that

$ cat file1
vg01 001 009 010 019
vg02 011 019 011 011
$
$ cat file2
/dev/rdsk/c49t0d0 M(8) EMC SYMMETRIX 5567 34001000 15697920
/dev/rdsk/c54t0d0 M(8) EMC SYMMETRIX 5567 34001000 15697920
/dev/rdsk/c49t0d1 M(8) EMC SYMMETRIX 5567 34009000 15697920
/dev/rdsk/c54t0d1 M(8) EMC SYMMETRIX 5567 34009000 15697920
$


$ cat concat.sh
#!/usr/bin/ksh
{
set -x
count=0
while read j
do
count=`expr $count + 1`
done < file2

num=0
while [ ${num} -lt ${count} ]
do
num=`expr $num + 1`
str1=`sed -n "${num}p" file2`
str2=`sed -n "${num}p" file1 | awk '{print $1}'`
echo "${str1} ${str2}" >> file3
done
} 2>/tmp/concat.log
$

$ ./concat.sh
$ cat file3
/dev/rdsk/c49t0d0 M(8) EMC SYMMETRIX 5567 34001000 15697920 vg01
/dev/rdsk/c54t0d0 M(8) EMC SYMMETRIX 5567 34001000 15697920 vg02
/dev/rdsk/c49t0d1 M(8) EMC SYMMETRIX 5567 34009000 15697920
/dev/rdsk/c54t0d1 M(8) EMC SYMMETRIX 5567 34009000 15697920

Just my two cents.

-Sukant


Who dares he wins
Rodney Hills
Honored Contributor

Re: Script question

How about this perl routine-

open(INP,"while() {
chomp;
@ary=split(" ",$_);
$vg=shift(@ary);
foreach $ix (@ary) {
$map{$ix}=$vg;
}
}
close(INP);
open(INP,"while()
chomp;
($ix)=/ 34(\d\d\d)/;
print $_," ",$map{$ix},"\n";
}

-- Rod Hills
There be dragons...
Rita C Workman
Honored Contributor

Re: Script question

Hi Rajman,

I did a little something for this exact same thing awhile back. Now I am not a programmer so my script is very 'juvenile'. I had 4 servers attached to 1 EMC Symmetrix - I used their inq utility and wrote my own scripts and had them rcp the result to 1 server where I combined all the files and produced a flat file sorted that I then imported into Excel and dressed up. I am not proficient enough to write the print code to get a good report via HPUX. Also 1 of the servers-I had to adjust my script since it used mass amounts of 'raw' (yes I said raw) volumes...and the inq utility will not show these as used (arghghg!).
Anyway...I wrote these little ditties and I'll be happy to email them to you if you want to take a look.

Mine puts it down to the filesystem (except for the raw devices, I could only get to the vg).
rworkman@wvbep.org

Rgrds,
Rita

Roger Baptiste
Honored Contributor

Re: Script question

Sree,
The luns in question are not yet assigned to a VG. I want to create a map to make the vg creation process easy. Yeah, i am brain-dead today ;-) BTW,Good to see you back.

Anyway, i came up with a two-script kludge which does what i am looking for:
---
while read -r vg d1 d2 d3 d4
do
grep -e 34$d1 -e 34$d2 -e 34$d3 -e 34$d4 syminq.out >>$vg.map
done
for i in `ls *.map`
do
while read -r d1 d2 d3 d4 d5 d6 d7
do
i1=`echo $i |awk '{FS="."; print $1}'`
echo "$d1 $d2 $d3 $d4 $d5 $d6 $d7 $i1" >>$i.new
done <$i
done
---
This creates a file vgname.map.new for each VG which has the corresponding Lun entries of the inq file appended to the vg name.
Sort of messy, but it deserves some points ;-)

Procura - i hope this explains on what i am looking for.

thanks

Take it easy.
H.Merijn Brand (procura
Honored Contributor
Solution

Re: Script question

Ahh, thanks to Rodney's script, I get what you mean. Rodney's script is failing a brace, but here's a more optimized (or obfuscated :) version.

@ARGV = ("vgfile");
while (<>) {
chomp;
($vg, @ary) = split " ";
@map{@ary} = ($vg) x @ary;
}

@ARGV = ("syminq.out");
while (<>) {
s/( 34(\d\d\d).*)/$1 $map{$2}/;
print;
}
Enjoy, Have FUN! H.Merijn