Tiny shell script to chase symbolic links to true file name 
Author Message
 Tiny shell script to chase symbolic links to true file name

I'd like to thank Jake for his post, even though I haven't tried it yet.
I would also like to throw this out for anyone that can use it --

With having inherited a diverse Informix environment,  I have had to battle
with trying to find out how things were
placed on disk, whether we were using raw -vs- blocked, links, etc...

So I created the following script which gens a report of the chunk names to
link, and whether it is raw / block.
Just have your env set for your engine and run it.

Hope some of you will find it useful - If you can make it better, please
let me know.  I'm always looking for better ways to do things.

Sincerely -

Eric P. Melillo
Sr. Database Administrator
Associated Grocers, Inc.
Seattle, WA  98118
vmail: (206) 767-8178

#========== SCRIPT BEGINS HERE ===========
#!/bin/ksh
#
# SCRIPT NAME : inf_disk
#
# WRITTEN BY  : Eric P. Melillo
# DATE WRITTEN: 10 OCT 1997
#
# PURPOSE     : To document the disk(s) utilized by informix,
#             :  - lists the chunks that exist
#             :  - what the links are ( if any )
#             :  - type of disk used (raw -vs- block).
#
# NOTES       : Works with both version 5.X and 7.X
#             : run it once for each Informix server(s)

SVRNAME=`hostname`

# Determine Engine Version
if [ -x $INFORMIXDIR/bin/onstat ]
then
   STAT="onstat"
   ENGINE=`env | grep ONCONFIG`
else
   STAT="tbstat"
   ENGINE=`env | grep TBCONFIG`
fi

# Get chunk information
$STAT -d |
  sed '1,5d' |
  awk 'BEGIN {i=0}
  {
    if ($1 == "Chunks")
       {i=1}
    if (i==1 && $1 != "address" && NF == 8)
       {printf("%s %s %s \n", $5,$7,$8)}
  }' > /tmp/inf_c.$$

# Get chunk-path information
for CPATH in `cat /tmp/inf_c.$$ | awk '{ print $3 }'`
do
  ls -al $CPATH | \
  awk 'BEGIN {i=0}
  {
    if (i==0 && NF == 11)
    {
      #
      # The following "if" stmt handles the case where someone created
      # a symbolic link in the same directory as the device driver and
      # did not full path the darn thing...
      #
      if ( substr($11,2,2) !~ /de/ )
      {
        split($9,dirarray,"\/")
        printf ("%s %s /%s/%s/%s\n",$9,$10,dirarray[2],dirarray[3],$11)
      }
      else
        printf ("%s %s %s\n",$9,$10,$11)
    }
    if (i==0 && NF == 10)
      {printf ("%s %s %s\n","fld9","fld10",$10)}
  }' >> /tmp/inf_l.$$

  # Get link-path information
  for LPATH in `cat /tmp/inf_l.$$ | awk '{ print $3 }'`
  do
    ls -al $LPATH | \
    awk 'BEGIN {i=0}
    {
    if (i==0)
      {printf ("%s %s\n",$1,$10)}
    }' >> /tmp/inf_d.$$
  done
  DEVPERM=`grep $LPATH /tmp/inf_d.$$ | \
           awk -v lpath=$LPATH '{if($10=lpath) {print $1}}'`

  echo "$CPATH -> $LPATH $DEVPERM" >> /tmp/inf_r.$$

done

echo "SERVER = $SVRNAME" >> /tmp/$SVRNAME.DBSPACE.RPT
echo $ENGINE >> /tmp/$SVRNAME.DBSPACE.RPT
echo "\n\n\n" >> /tmp/$SVRNAME.DBSPACE.RPT

cat /tmp/inf_r.$$ |
awk '{printf ("%-40s %-4s %-28s %3s\n", $1,$2,$3,substr($4,1,1))}' >>
/tmp/$SVRNAME.DBSPACE.RPT

pr -l60 /tmp/$SVRNAME.DBSPACE.RPT | lp

rm /tmp/inf_c.$$
rm /tmp/inf_l.$$
rm /tmp/inf_d.$$
rm /tmp/inf_r.$$
rm /tmp/$SVRNAME.DBSPACE.RPT
#==========   SCRIPT ENDS HERE    ===========

Hi all.
I wrote this shell script to ease some aspects of Informix
administration. I am cross posting it because it has general use. Here
it is:
---------------------------- CUT HERE ----------------------------------
#!/bin/ksh
# truename - chase down theain of symbolic links to obtain the true
#            name of a file
# Parameters: Name of a file or a list of file names
#
# Author: Jacob Salomon

# Date:   August 12 1998
# Shell function chase1 - Chase 1 file name to its true name
# Parameter: The file name
chase1 ()
{
  PFN=$1
  # Get link name, if any. If there is no symbolic link, the loop
  # below will not need to start.
  #
  ls -ld $PFN | awk '{print $NF}' | read link_name
  until [ "$link_name" = "$PFN" ]   # chase it until no further links
  do
    PFN=$link_name                  # Reset for next round of loop
    ls -ld $PFN | awk '{print $NF}'|read link_name
  done
  echo $link_name

Quote:
}

for FN in $*
do
  chase1 $FN | read TN          # Get any name this file might link to
# echo $FN : $TN
  echo $TN
done
---------------------------- CUT HERE ----------------------------------
--
   -- Jake (Retrospectively realizes there is no future in hindsight)
+------------------------------------------------------------+
| The expedient performance of a task with excessive concern |
| regarding its duration-to-completion engenders a virtual   |
| certainty of diminished benefit therefrom.                 |
|          -- Benjamin Franklin (but he said it in 3 words)  |
+------------------------------------------------------------+


Wed, 18 Jun 1902 08:00:00 GMT
 
 [ 1 post ] 

 Relevant Pages 

1. Tiny shell script to chase symbolic links to true file name

2. Execute a shell script from a stored procedurExecute a shell script from a stored proceduree

3. Database Link creation with Global name TRUE

4. symbolic link / virtual database

5. Avoiding Symbolic Links in setting ORACLE_HOME variable on UNIX

6. Symbolic Links During Oracle Server Upgrade

7. Install Oracle on symbolic link directory

8. Symbolic Link Oracle8i Linux

9. Symbolic Link Oracle8i Linux

10. using symbolic links with ORACLE_HOME variable in unix - WARNING

11. Symbolic link pointing to Oracle Home

12. Changing to symbolic links


 
Powered by phpBB® Forum Software