#!/bin/csh -f
#
# This script finds all "/tmp" directories and prints their names
# to stdout
#
# If the "diskconfig.disktest" file exists, then the names from
# the file are used instead of being automatically determined.
# 
set path = ( /usr/etc /usr/bin /usr/ucb /usr/diag/sysdiag )

set nonomatch
#
# diskconfig.disktest file must be formatted as follows:
# /dev/sd0a /dev/sd1a /dev/sd3a ... etc
#
if (-e diskconfig.disktest && -r diskconfig.disktest) then
    set DISKs = `cat diskconfig.disktest`
else
    #
    # locate mounted disks "a" (/) partition
    #
    set DISK_tmp = `mount | egrep "[sx]d[0-9]a"\|"[sx]d[1][0-5]a" | awk '{print $1}'`
    #
    # if no root partition located, locate "g" (/usr) partitions
    #
    if ($#DISK_tmp == 0) then
	set DISK_tmp = `mount | egrep "[sx]d[0-9]g"\|"[sx]d[1][0-5]g" | awk '{print $1}'`
    endif
    set DISKs = "$DISK_tmp"
endif

#
# print out each "/tmp" and "/usr/tmp" directory located 
#
set STRING
foreach i ($DISKs) #{
    set MOUNTED = `mount | grep $i | awk '{if (index($1,"/dev")) print $3;}'`	
    if ("$MOUNTED" == '/') then 
        set MOUNTED = /tmp
    else if ("$MOUNTED" == "/usr") then
		set MOUNTED = /usr/tmp
    endif

	set STRING = ($STRING $MOUNTED)
end
echo "$MOUNTED"
exit
