?
Solved

Need script to rebuild soft links

Posted on 2000-04-12
4
Medium Priority
?
269 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 1000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

When you do backups in the Solaris Operating System, the file system must be inactive. Otherwise, the output may be inconsistent. A file system is inactive when it's unmounted or it's write-locked by the operating system. Although the fssnap utility…
This tech tip describes how to install the Solaris Operating System from a tape backup that was created using the Solaris flash archive utility. I have used this procedure on the Solaris 8 and 9 OS, and it shoudl also work well on the Solaris 10 rel…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
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…
Suggested Courses

770 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