#This program will do a recursive read starting from the root directory
#and pull off all symbolic links.  It also creates a file that can be
#imbedded into a script file on the host.  Use the "tohost" command to
#upload the file
 
trap 'rm /tmp1$$ /tmp2$$ /tmp3$$' 1 2 3 15

if [ "$LOGNAME" = "root" ]
then 
  :
else
  echo "===> YOU MUST BE LOGGED IN AS ROOT FOR THIS SHELL SCRIPT TO EXECUTE PROPERLY"
  exit 1
fi 

cd /
abspath='/' 

rm getsym.out1 getsym.out1.err 2> /dev/null
rm getsym.out2 getsym.out2.err 2> /dev/null

ls -alR  | while read lsperm lslink lsowner lsgroup lsbyte lsmonth lsday \
            lstime lsname lsarrow lsrestofit
  		do
		  case $lsperm in                   #translate ls dir name
		    './'*':')
			echo $lsperm > /tmp1$$
			tr -s './' '/' < /tmp1$$ > /tmp2$$
			tr ':' '/' < /tmp2$$ > /tmp1$$
			abspath=`cat /tmp1$$`          #create fullpath name
		  esac
			
		  if  [[ -L $abspath$lsname ]]
  		  then
		     echo $abspath$lsname $lsarrow $lsrestofit \
                          >> getsym.out1 2>> getsym.out1.err
		     echo $lsrestofit '<-' $abspath$lsname     \
                          >> /tmp3$$ 2>> getsym.out2.err
  		  else
	            :
		  fi
	        done
 
 
sort -b +0 -2 /tmp3$$ -o getsym.out2  #sort for 3.2 links to 3.1
rm /tmp1$$  /tmp2$$ /tmp3$$           #housekeeping
