Finding symbolic links


What is this stuff?

If this isn't exactly what you wanted, please try our Search (there's a LOT of techy and non-techy stuff here about Linux, Unix, Mac OS X and just computers in general!):

See Upgrades vs. Fresh installs also.


Hate these ads?



Xref: world comp.unix.sco.misc:97146
Newsgroups: comp.unix.sco.misc
Path: world!newsfeed.mathworks.com!nntp.flash.net!mercury.cts.com!nntp2.cerf.net!nntp3.cerf.net!xenitec!news
From: rac@tenzing.org (Roger Cornelius)
Subject: Re: Recommendations on upgrading from 504 to 505
Resent-From: mmdf@xenitec.on.ca
Submit-To: scomsc@xenitec.on.ca
Organization: [resent by] The SCOMSC gateway and Propagation Society
Date: Sun, 23 May 1999 21:02:12 GMT Message-ID: <199905232102.RAA27768@tenzing.org> References: <4.1.19990523140233.0234b520@scogr1.dmg-grsd.com> <19990523144131.C22323@jpradley.jpr.com>
Sender: news@xenitec.on.ca (xenitec.on.ca News Administrator)
Precedence: list
Lines: 138
X-Mozilla-Status: 8011



Jean-Pierre Radley <jpr@jpr.com> wrote:
>
>Ken Wolff averred (on Sun, May 23, 1999 at 06:20:28PM +0000):
>| 
>| I also have JP's 'savefiles' script (been using
>| this for quite a few upgrades - thanks JP).
>
>You're welcome.  But please get the latest version of savefiles from
>ftp.jpr.com.
>
>The script makes us of BackupEDGE's h flag:
>
>  h  Restore the data in addition to the symbolic link. If this flag is set
>     and symbolic link is restored, AND if the symbolic link point to a real
>     file which is stored later on the archive, the real file is also
>     restored.
>
>It literally means what it says; but in earlier versions of "savefiles",
>I had included a few directories; the contents of those directories
>didn't get saved if the directory itself was a symlink. /usr/spool/cron,
>for example.



Here's a script I've been meaning to post for a long time.  I use it
along with your savefiles script to help restore the state of my system
after an upgrade or restore.  Depending on the options used, it produces
a list of symlinks on the root fs which point to objects on non-root
filesystems, a list of symlinks on non-root filesystems which point to
the root fs, or both.  It will optionally produce the list in a form
suitable for execution by the shell.














Any comments or suggestions are welcome.



---- cut here ----
:
# @(#) findln: print list of symlinks pointing to/from root filesystem
# @(#) Assumes all filesystems are currently mounted
# @(#) Requires Gnu find
# @(#) 08/25/97 rac@tenzing.org



# The following can be useful in building a script to reconnect symlinks
# after an OS upgrade, etc..
# findln -nr | sed 's/^\(.*\) -> \(.*\)/ln -s \2 \1/'
#  or
# findln -lnr



arg0=`basename $0`



# location of gnu find
FIND=/u/gnu/bin/find



if expr "`id`" : ".*(root) *" >/dev/null
then
    : ok
else
    echo "Must be root" >&2
    exit 2
fi









usage() {
    echo "Usage: $arg0 [-l] [-n] [-r]
where:
-n  print symlinks on non-root filesystems pointing to root filesystem
-r  print symlinks on root filesystem pointing to non-root filesystems
-l  print in format suitable for execution by /bin/sh" >&2
    exit 1
}



# find symlinks on root filesystem which point to non-root filesystems
do_root_fs() {



    echo "\n#\n# symlinks on root filesystem\n#"



    # create -lname command list for gnu find
    pat=
    for fs in $mountlist
    do
        case $fs in
        /|/stand)   # skip root and stand filesystems
            ;;
        *)  pat="$pat ${pat:+-o} -lname '${fs}/*'";;
        esac
    done



    sh -c "$FIND / -mount \( $pat \) -printf '$printf_fmt'"
}



# find symlinks on non-root filesystems which point to / or /stand filesystems
do_nonroot_fs() {



    echo "\n#\n# symlinks on non-root filesystems\n#"



    # create -lname command list for gnu find
    # don't match any symlink whose contents don't begin with '/'
    pat="! -lname '[!/]*'"
    for fs in $mountlist
    do
        case $fs in
        /|/stand)
            ;;
        *)  pat="$pat ${pat:+-a} ! -lname '${fs}/*'";;
        esac
    done



    # for each fs, search for symlinks to / or /stand
    for fs in $mountlist
    do
        # skip root and stand filesystems
        case $fs in /|/stand) continue ;; esac



        sh -c "$FIND $fs -mount -type l \( $pat \) -printf '$printf_fmt'"
    done
}




# default printf format
printf_fmt="%p -> %l\n"



do_root=false do_nonroot=false
while getopts lnr opt 
do
    case $opt in
    l)  printf_fmt="ln -s %l %p\n";;
    n)  do_nonroot=:;;
    r)  do_root=:;;
    *)  usage;;
    esac
done



# skip /dev/cd* and /dev/hd[0-9]d (cdrom drives and dos partitions)
mountlist="`/etc/mount | sed '/\/dev\/cd/d; /\dev\/hd[0-9]d/d; s/ .*//'`"



$do_root && do_root_fs
$do_nonroot && do_nonroot_fs
---- cut here ----



-- 
Roger Cornelius        rac@tenzing.org








Enter your email address for automatic notification of new posts here
(be sure to whitelist 'feedburner.com' if you use spam filtering)

Or use any RSS reader

Delivered by FeedBurner


M3IP inc.

Views for this page
Today This Week This Month This Year  Overall
44661,011 3,770

/Bofcusm/46.html copyright 1997-2004 (various authors) All Rights Reserved

Have you tried Searching this site?

Unix/Linux/Mac OS X support by phone, email or on-site: Support Rates

This is a Unix/Linux resource website. It contains technical articles about Unix, Linux and general computing related subjects, opinion, news, help files, how-to's, tutorials and more. We appreciate comments and article submissions.

Publishing your articles here

More:
       - Installation/Upgrades




Unix/Linux Consultants


http://bcstechnology.net Full service Linux & UNIX systems integrator; Windows to UNIX/Linux Client-Server Specialist; Secure E-Mail & Website Hosting; Thoroughbred Software Developer; Custom Industrial Automation; Hardware & Electronics Experts; In Business Since 1985.


http://www.vss3.com SCO/Caldera OpenServer, Unixware & Linux. Tarantella & Non-stop Clustering


http://thatitguy.com Business networking servers, Linux and Unix experts. In business since 1997! Windows and Exchange to Samba and Scalix migration experts.



Twitter
  • Nov 23 13:01
    I need coffee before I will even open the door, never mind go out there. That's completely non-negotiable, by the way.
  • Nov 23 12:56
    It's COLD and my wife wants us to go work in the yard. Do you think I can have her arrested for cruelty? Probably not as she's going too.




card_image








Change Congress


Related Posts