Solved

Need script to rebuild soft links

Posted on 2000-04-12
4
267 Views
Last Modified: 2010-04-21
Here's the problem,

When I refesh a developement environment from a tape backup of production, there are a lot of softlinks in many different subdirectories that need to be rebuilt, so it links to the right files.

Can I get a script that can take the directory name that needs changed, the directory name that it needs changed to, and the full path to the directory so any subdirectorieswith bad links will get fixed.

here's an example of what I'm talking about...

in

/ORACLE/apps/DEV1/eper/1.0.0/bin

there are many links like

lrwxrwxrwx   1 applmgr    apps            57 Mar 30 13:05 HRPSRSRE -> /ORACLE/apps/PROD1/fnd/6.1.1/bin/fndcpesr

Basically I need a quick way of changing all links from PROD1 to DEV1 (The sub-directory structures are the same between production and developement)

Ideally, the command would look something like

change_links.sh PROD1 DEV1 /ORACLE/apps/DEV1

I'm running on HPUX 10.20 if that helps.

If I am unclear about anything please let me know.

And please post comments, not answers, I will accept your comment as an answer, when I verify that everything works.


0
Comment
Question by:mboss
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 21

Accepted Solution

by:
tfewster earned 250 total points
ID: 2708229
change_links.sh:

#!/bin/sh
# Usage: change_links.sh OLDDIR NEWDIR LINK

OLDDIR=$1
NEWDIR=$2
LINK=$3

# Check links
echo
echo Link $LINK
echo `ls -l $LINK | awk '{ print $9 $10 $11}'`
echo becomes
echo `ls -l $LINK | awk '{ print $ 11}' | sed s/$OLDDIR/$NEWDIR/g`

# Change links
#ln -f -s `ls -l $LINK | awk '{ print $ 11}' | sed s/$OLDDIR/$NEWDIR/g` $LINK


To use this, call it from a "find", e.g.
find /oracle/apps/DEV1 -type l -exec ~/test/change_links.sh PROD1 DEV1 {} \;

Note that it just tests the links for now, & echos what it finds + what it WOULD do when you
uncomment the "ln ..." line

It will go wrong if you have a directory PROD1 under DEV1...
0
 
LVL 21

Expert Comment

by:tfewster
ID: 2708333
I've put an addditional check in, so if the links found don't contain the string $OLDDIR, they are just ignored (My previous script would have rewritten them, which is pointless & asking for trouble...)

change_links.sh:

#!/bin/sh
# Usage: change_links.sh OLDDIR NEWDIR LINK

OLDDIR=$1
NEWDIR=$2
LINK=$3

#test if $LINK contains string $OLDDIR
TARGET=`ls -l $LINK | awk '{ print $ 11}'|grep $OLDDIR`
echo $TARGET

if [ ! X$TARGET = X ]
then
  # Check links
  echo
  echo Link $LINK
  echo `ls -l $LINK | awk '{ print $9 $10 $11}'`
  echo becomes
  echo `ls -l $LINK | awk '{ print $ 11}' | sed s/$OLDDIR/$NEWDIR/g`

  # Change links
  #ln -f -s `ls -l $LINK | awk '{ print $11}' | sed s/$OLDDIR/$NEWDIR/g` $LINK
fi
0
 

Author Comment

by:mboss
ID: 2708357
Excellent.  Thanks for all your help.  Can you recommend a good book/site to learn sed and awk?  

I raised the points to 300 cause you deserve it.

Thanks again

mboss
0
 

Author Comment

by:mboss
ID: 2708370
woops...I think I forgot to rasie the points like I said I would.  I'll post them for you an a sec.

Sorry about that.

mboss
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

My previous tech tip, Installing the Solaris OS From the Flash Archive On a Tape (http://www.experts-exchange.com/articles/OS/Unix/Solaris/Installing-the-Solaris-OS-From-the-Flash-Archive-on-a-Tape.html), discussed installing the Solaris Operating S…
Java performance on Solaris - Managing CPUs There are various resource controls in operating system which directly/indirectly influence the performance of application. one of the most important resource controls is "CPU".   In a multithreaded…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question