(OLDER) <- More Stuff -> (NEWER) (NEWEST)
Printer Friendly Version



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.

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




Click here to add your comments



Don't miss responses! Subscribe to Comments by RSS or by Email

Click here to add your comments


If you want a picture to show with your comment, go get a Gravatar




/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

Jump to Comments



Many of the products and books I review are things I purchased for my own use. Some were given to me specifically for the purpose of reviewing them. I resell or can earn commissions from the sale of some of these items. Links within these pages may be affiliate links that pay me for referring you to them. That's mostly insignificant amounts of money; whenever it is not I have made my relationship plain. I also may own stock in companies mentioned here. If you have any question, please do feel free to contact me.

Specific links that take you to pages that allow you to purchase the item I reviewed are very likely to pay me a commission. Many of the books I review were given to me by the publishers specifically for the purpose of writing a review. These gifts and referral fees do not affect my opinions; I often give bad reviews anyway.

We use Google third-party advertising companies to serve ads when you visit our website. These companies may use information (not including your name, address, email address, or telephone number) about your visits to this and other websites in order to provide advertisements about goods and services of interest to you. If you would like more information about this practice and to know your choices about not having this information used by these companies, click here.



More:
       - OSR5
       - Bofcusm


Unix/Linux Consultants

Skills Tests

Guest Post Here











My Favorites

Change Congress