1830935 Members
2240 Online
110017 Solutions
New Discussion

string parsing

 
andi_1
Frequent Advisor

string parsing

Hi,

Sorry for my questions which might sound silly - didn't have much experience in bourne shell scripting and don't have any books!

I do the following to get PV name:
diskName=`vgdisplay -v|awk '$1 == "PV" && $2 == "Name" {print $3 }'`

diskName = contains now /dev/dsk/c0t01d0

I need to use diskinfo on the disk, and it needs character devices, /dev/rdsk/c0t01d0

What is the best to add I guess R into /dev/Rdsk/c0t01do?

Thanks a lot!
8 REPLIES 8
Darrell Allen
Honored Contributor

Re: string parsing

disk=`echo $diskName | cut -c10-`

Now simply specify /dev/rdsk/$disk

Note, it's a little "r" in rdsk.

Darrell
"What, Me Worry?" - Alfred E. Neuman (Mad Magazine)
A. Clay Stephenson
Acclaimed Contributor

Re: string parsing

Hi:

How about:
RAWDISK=$(echo "${diskName}" | sed '/dsk/s//rdsk')

echo "${RAWDISK}"

The $( ... ) is the preferred method of doing
` ... ` in the POSIX shell.
If it ain't broke, I can fix that.
S.K. Chan
Honored Contributor

Re: string parsing

I got a silly way for you ..

diskName=`vgdisplay -v|awk '$1 == "PV" && $2 == "Name" {print $3 }'| awk -F"/" '{print $4}'`

which gives you c0t01d0

then you would ..

diskPATH=/dev/rdsk/$diskName



Gary George
New Member

Re: string parsing

# diskName='/dev/dsk/c0t4d0'
# rdiskName=`echo $diskName|sed -n s/dsk/rdsk/gp`
# echo $diskName $rdiskName
/dev/dsk/c0t4d0 /dev/rdsk/c0t4d0
#

Mind you, I got a few more disk devices from your initial line:

# diskName=`vgdisplay -v|awk '$1 == "PV" && $2 == "Name" {print $3 }'`
# echo $diskName
/dev/dsk/c0t3d0 /dev/dsk/c0t4d0 /dev/dsk/c0t5d0 /dev/dsk/c0t6d0 /dev/dsk/c0t5d0 /dev/dsk/c0t4d0 /dev/dsk/c5t4d0 /dev/dsk/c1t4d0 /dev/dsk/c1t5d0 /dev/dsk/c5t5d0 /dev/dsk/c5t8d0 /dev/dsk/c1t8d0 /dev/dsk/c6t8d0 /dev/dsk/c6t10d0 /dev/dsk/c6t8d6 /dev/dsk/c6t10d6 /dev/dsk/c6t8d1 /dev/dsk/c6t10d1 /dev/dsk/c6t10d2 /dev/dsk/c6t8d2 /dev/dsk/c6t8d5 /dev/dsk/c6t10d5
#

Gary
Scott Van Kalken
Esteemed Contributor

Re: string parsing

put this on the next line

echo $disk | sed 's/dsk/rdsk/g'


this replaces the term dsk with rdsk globally.

Scott.
Darrell Allen
Honored Contributor

Re: string parsing

To handle multiple physical volumes (which you would get if the VG contained more than one) you could do something like:

for diskName in `vgdisplay -v|awk '$1 == "PV" && $2 == "Name" {print $3 }'`
do
disk=`echo $diskName | cut -c10-`
diskinfo /dev/rdsk/$disk
done

Darrell
"What, Me Worry?" - Alfred E. Neuman (Mad Magazine)
SHABU KHAN
Trusted Contributor

Re: string parsing

Hi Leon,

I usually like to use /etc/ioscan instead of vgdisplay...

Here is another method:

for i in `/etc/ioscan -kfnC disk | awk '/dsk/{print $2}'`
do
/etc/diskinfo ${i}
done

Thanks,
Shabu
Robin Wakefield
Honored Contributor

Re: string parsing

Hi Leon,

...or even:

diskName=$(vgdisplay -v|awk '$0 ~ "PV Name"{sub("dsk","rdsk",$3);print $3}')

Rgds, Robin