Originally posted by: Nothinman
That looks about right, but I don't think -exec will take shell constructs so you could just create rmlink.sh and put the "should I delete this?" code in there.
Originally posted by: esun
I don't think you can use the wildcard there, but bash supports regular expressions so I'd use one of those.
Originally posted by: Nothinman
The main problem is that readlink just returns the string that the symlink points to not a real pathname. So if you have a link named blah pointing to /dev/null readlink will return "/dev/null" but if the link just points to null you'll just get "null" no matter where you run readlink from.
#!/bin/bash
# Creating Shadow Copies
# The snapshot name used in the mount path
SNAP=Snap1
# removing symlinks
for link in $( find /export/share -maxdepth 2 -type l ); do
if [[ `readlink $link` =~ "^/export/snaps/${SNAP}.*" ]]; then
rm $link
fi
done
# remove My Documents links
for link in $( find /export/homes -maxdepth 3 -type l ); do
if [[ `readlink $link` =~ "^/export/snaps/${SNAP}.*" ]]; then
rm $link
fi
done
echo "symlinks deleted..."
# end of deleting links
#### This is where your code would go for removing the old snapshot and creating a new one
#### I use a proprietary app called admsnap to do this, so this part of my script would
#### not do most people any good unless they owned an EMC Clariion CX300.
SHADOWNAME=`date -u +%Y.%m.%d-%H.%M.%S`
echo "creating the plethora of symlinks..."
# "share" nested mappings
for directory in $( find /export/share -maxdepth 1 -type d ); do
TARGET=`echo $directory | sed "s/^\/export\/share/\/export\/snaps\/${SNAP}\/share/"`
ln -s $TARGET ${directory}/@GMT-$SHADOWNAME
done
# the redirected My Documents directories
for directory in $( find /export/homes -maxdepth 2 -type d ); do
TARGET=`echo $directory | sed "s/^\/export\/homes/\/export\/snaps\/${SNAP}\/homes/"`
ln -s $TARGET ${directory}/@GMT-$SHADOWNAME
done
echo "links created..."
echo "done."