#!/bin/sh

nawk '

# ctstat V2.1	bugs-to: paulr@Eng	Wed May 14 12:21:59 PDT 1997
#
# Join on geographic name /io.../.../sd@
#
# arr[geoname] = cxtxname
#
BEGIN	{ 

	# pluck the geoname and cxtxname out of the symlinks to load array

	while ("ls -l /dev/dsk/c*t*d*s0" | getline) 
		if ( $(NF-1) == "->" )	{
			# strip gname of leading ../../devices and trailing :a
			gname = substr($NF, 14, length($NF)-15)
			# strip ctname of leading /dev/dsk/ and trailing s0
			ctname = substr($(NF-2), 10, length($(NF-2))-11)
			arr[gname] = ctname
			}


	# now look up the sd and ssd instances
        if ( length(ENVIRON["PATH_TO_INST"]) > 0 )
            P=ENVIRON["PATH_TO_INST"]
        else
            P="/etc/path_to_inst"

        while (getline<P >0) {
		# for sd and ssd devices, the device type is in column 1 and
		# lies between the last / and the @
		# Note: easier in Solaris >= 2.5 - extra column#3 is devtype!
		gname=substr($1,2,length($1)-2)		#strip quotes
		devinst=$2
		num = split($1,pathcomp,"/")
		split(pathcomp[num],subcomp,"@")
		devtype=subcomp[1]
                if ((devtype == "sd") || (devtype == "ssd")) {
                        if (gname in arr)
				printf("%-8s %-8s %s\n", arr[gname], devtype devinst, 
					gname)
                }
        }
	exit
} ' | sort

