Nov 16, 2014

Recreate Symbolic Links after Oracle Instance Refresh

After the non-Production instances (DEV, QA, TEST, etc) are refreshed, you may have noticed that the symbolic links, that are used for host program files, get overwritten by Production links and are still pointing to Production locations. To have the links work for that instance, you will have to delete the old symbolic links and recreate them.

Below is a bash shell script which can be run anywhere in UNIX. I would save the file as "xxrl_recreate_symlinks.sh" and execute as follow: 

%> ./xxrl_recreate_symlinks.sh

Note:

Please make sure the following are completed before you run the script:

1) File is executable:
%> chmod 777 xxrl_recreate_symlinks.sh

2) The .env file sets the $XX_TOP for that instance based on your company custom top.


#!/bin/sh

##*******************************************************************************************
## File Name         : xxrl_recreate_symlinks.sh
## File Location     : $XXRL_TOP/bin
## Created By        : Abul Mohsin
## Creation Date     : June 21, 2014
## Description       : This program deletes the old Symbolic Links that are copied over from
##                      PROD refresh, then recreates them for that instance. If no *.prog
##                      files found, the program simply exists.
##
## Program Language  : Shell Script
## Specific Module   : Generic for all modules
## Create SymLink    : %> chmod 755 xxrl_data_ldr.prog
##                     %> ln -s $FND_TOP/bin/fndcpesr xxrl_data_ldr
##
## Execute Command   : %> ./xxrl_recreate_symlinks.sh
##
##*******************************************************************************************
## Modification History :  (Date,  Version, Programmer, Change Description)
##-------------------------------------------------------------------------------------------
## 06/21/14   1.0   Abul Mohsin      Initial version
##
##*******************************************************************************************

##----------------------------------------------------
##-- set these variables based on user preference
##---------------------------------------------------- 
customTop=$XX_TOP         ##-- this is based on company's custom top

##----------------------------------------------------
##-- set these variables based on user preference
##----------------------------------------------------
fileExt="prog"            ##-- usually .prog file in Oracle
debugMode='N'             ##-- use 'Y' if you need to display everything

##----------------------------------------------------
##-- set up local variables based on previous ones
##----------------------------------------------------
binDir=${customTop}/bin
echo ' '
echo binDir=$binDir


##-- go to BIN directory first
cd $binDir

if [ "$debugMode" = 'Y' ]; then
  pwd
fi

##----------------------------------------------------
##-- get the number of symbolic link files from BIN dir
##----------------------------------------------------
fileListCnt=`ls *.${fileExt} | sed 's/\.[^.]*$//' | wc -l`

echo "${fileExt} File Count $fileListCnt"
echo ' '

##----------------------------------------------------
##-- if 1 or more files found in the BIN directory,
##-- then, get the symbolic link files from BIN directory
##----------------------------------------------------
if [ $fileListCnt -gt 0 ]; then

  fileList=`ls *.${fileExt} | sed 's/\.[^.]*$//'`

  for fileName in ${fileList};
  do
   
    ##----------------------------------------------------
    ##-- check if the file exists and is a symbolicLink
    ##----------------------------------------------------
    if [ $debugMode = 'Y' ]; then
      echo "SymbolicLink fileName="$fileName
    fi

    ##----------------------------------------------------
    ##-- check if the file exists and is a symbolicLink
    ##----------------------------------------------------
    if [[ -f "$fileName" && -L "$fileName" ]]; then
     
     
      ##----------------------------------------------------
      ##-- first, remove the SymbolicLink file
      ##----------------------------------------------------
      echo "  Deleting SymbolicLink $fileName"
     
      rm $fileName
     
      retCode=$?
     
      if [ $retCode != 0 ]; then
        echo "File $fileName was not removed. Please re-verify."
      fi

      ##----------------------------------------------------
      ##-- Recreating SymbolicLink file
      ##----------------------------------------------------
      echo "  Recreating SymbolicLink for $fileName.$fileExt"

      ln -s $FND_TOP/bin/fndcpesr $fileName

      retCode=$?

      if [ $retCode != 0 ]; then
        echo "SymbolicLink $fileName was not created. Please check the .prog file."
      fi

    ##----------------------------------------------------
    ##-- if the file is not a SymbolicLink, show err msg
    ##----------------------------------------------------
    else
      echo "  $fileName is NOT a symlink"
    fi
   
    echo ' '

  done

else
  echo "No SymbolicLink files found"
  echo "Exiting the program"
fi

exit