Re: Script question (828 Views)
Reply
Honored Contributor
Roger Baptiste
Posts: 1,151
Registered: ‎04-17-2000
Message 1 of 19 (828 Views)
Accepted Solution

Script question

[ Edited ]

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.
Honored Contributor
H.Merijn Brand (procura
Posts: 6,188
Registered: ‎10-13-1997
Message 2 of 19 (828 Views)

Re: Script question

What is the joinable data?

34001000 == 001 009 010 019
Enjoy, Have FUN! H.Merijn
Honored Contributor
Sridhar Bhaskarla
Posts: 6,350
Registered: ‎08-15-2001
Message 3 of 19 (828 Views)

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
Honored Contributor
Roger Baptiste
Posts: 1,151
Registered: ‎04-17-2000
Message 4 of 19 (828 Views)

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.
Honored Contributor
H.Merijn Brand (procura
Posts: 6,188
Registered: ‎10-13-1997
Message 5 of 19 (828 Views)

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
Trusted Contributor
Sukant Naik
Posts: 192
Registered: ‎06-10-1999
Message 6 of 19 (828 Views)

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
Honored Contributor
Rodney Hills
Posts: 1,679
Registered: ‎09-09-1996
Message 7 of 19 (828 Views)

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...
Honored Contributor
Rita C Workman
Posts: 3,791
Registered: ‎08-03-2000
Message 8 of 19 (828 Views)

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

Honored Contributor
Roger Baptiste
Posts: 1,151
Registered: ‎04-17-2000
Message 9 of 19 (828 Views)

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.
Honored Contributor
H.Merijn Brand (procura
Posts: 6,188
Registered: ‎10-13-1997
Message 10 of 19 (828 Views)

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
Honored Contributor
harry d brown jr
Posts: 8,418
Registered: ‎12-12-2000
Message 11 of 19 (828 Views)

Re: Script question

see attached perl script. Simple and straight forward, though not too elegant.

live free or die
harry
Live Free or Die
Honored Contributor
Sridhar Bhaskarla
Posts: 6,350
Registered: ‎08-15-2001
Message 12 of 19 (828 Views)

Re: Script question

Raj,

Got it..

Look at this

vgfile is your VGfile
inq.out is your syminq.out
Look at out file after running this script.

---start of the script

while read LINE
do
#you may need to modify the following if your sample changes

INQ=`echo $LINE |awk '{print $6}'|cut -b 3-5`


while read vgline
do
echo $vgline |grep $INQ > /dev/null 2>&1
if [ $? = 0 ]
then
VG=`echo $vgline|awk '{print $1}'`
echo $LINE $VG >> out
fi
done < vgfile

done < inq.out

---end of the script----

See if it works...


-Sri
You may be disappointed if you fail, but you are doomed if you don't try
Honored Contributor
Rodney Hills
Posts: 1,679
Registered: ‎09-09-1996
Message 13 of 19 (828 Views)

Re: Script question

Ya know, with all these scripts, it would sure help if our replies didn't have the preceding spaces removed so that proper indenting could be kept for readability.

My 2 cents

-- Rod Hills
There be dragons...
Honored Contributor
Roger Baptiste
Posts: 1,151
Registered: ‎04-17-2000
Message 14 of 19 (828 Views)

Re: Script question

Thanks for the variety of script solutions. Didn't yet get a chance to go through all of them. I thought Procura's script was slick.
(procura: i made one change replacing the \d\d\d with \w\w\w , since the search is from 0-F and not just decimals).
I will assign points later during the day;

cheers
-raj
Take it easy.
Honored Contributor
Carlos Fernandez Riera
Posts: 1,172
Registered: ‎09-16-1998
Message 15 of 19 (828 Views)

Re: Script question

Well if you have syminq yet.... I know it as inq.HP. The unsupported Charlys tools Collection...


Try these.... Two shs.


1- first file.sh : run on each box connected to symmetrix

2- put all files.dat in a box.

3- Edit file2.sh and change box1 by hostname. etc.

change email address
4- Run file2.sh


SEE SOURCE FIRST.

unsupported
Honored Contributor
Carlos Fernandez Riera
Posts: 1,172
Registered: ‎09-16-1998
Message 16 of 19 (828 Views)

Re: Script question

The second...
unsupported
Esteemed Contributor
Ceesjan van Hattum
Posts: 478
Registered: ‎03-06-2002
Message 17 of 19 (828 Views)

Re: Script question

Hi RaiMan,

It seems that you're already satisfied with some answers. I did not see your comment and no assigned points while i was working out an effective script.
Although my solution is a bit late, i post my solution, because it is really simple:

while read x
do
vg=`echo $x |cut -f1 -d' '`
for i in $x
do
awk -v vg=$vg /$i/'{print $0" "vg}' file2
done

done < file1

..where file1 is the vg-file and file2 the device-file. It simply search xxx in the big file, and prints with vg-name.
Maybe not the price for beautiness, but effective it s.

Regards,
Ceesjan
Honored Contributor
Roger Baptiste
Posts: 1,151
Registered: ‎04-17-2000
Message 18 of 19 (828 Views)

Re: Script question

Carlos, the script looks intresting. I will check it up and get back with feedback/points. Ditoo to Ceesjan (even though it is much straightforward ;-) )

thanks
Take it easy.
Occasional Visitor
chandoo
Posts: 1
Registered: ‎01-05-2006
Message 19 of 19 (828 Views)

Re: Script question

Hi All

Thanks for the valuable information.
I have a situation.
we have emc symmetrix,
all my servers are looking at all the disks and devices.
If we expand a file system on Server A, we are in a situation of over-writing file system on server B or C or D .
I am figuring it out on how to use disks that are not used on any server while expanding the existing file systems or creating new file systems.
Can any one give me some comments.
my email id is chandra.sekhar@ipaper.com
Love to work on UNIX
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation.