This is how I do it
#!/usr/bin/ksh
# ###############################################################################
#AUTHOR: Ed Skolnik
#MODIFIED: 2003/08/11 Created
# Purpose to properly To properly delete a Legato Networker client
# and to clean up all Legato Networker databases.
# The nsradmin program does not purge the Media or Client file Index's
#
# ###############################################################################
display_message () {
case $1 in
A|a) message_level="ALERT";;
I|i) message_level="INFORMATION";;
W|w) message_level="WARNING";;
*) message_level="";;
esac
if [ -r $tmpmessage -a -w $tmpmessage ]; then
:
else
echo "$(basename $0) Error in calling display_message function "
exit 69
fi
mailx -s"$message_level $(basename $0) $(uname -n) $message_level $(who am i | awk '{print $1}' )" -c $mailto < $tmpmessage
cat $tmpmessage
rm $tmpmessage
}
# ###################################################################
# # M A I N L I N E
# ##################################################################
#
# Declare environment variables here
#
nsrlog=/nsr/logs/daemon.log
mailto='root'
tmpmessage=/tmp/$(basename $0)_message.$$
tmpclients="/tmp/$(basename $0)_clients.$$"
#
if [ $# -ne 1 ]; then
echo " "
echo "usage: "
echo "$0 clientname "
echo " "
echo "Aborted "
exit 69
fi
touch /tmp/a.$$
root=`ls -l /tmp/a.$$ | awk '{print $3}'`
rm /tmp/a.$$
if [ "$root" = "root" ];then
:
else
echo "In order to run this script you must be root"
exit
fi
client="${1:-nowayinhell}"
echo "client $client"
nsradmin <<EOF | sed 's/nsradmin>//g' |sed 's/;//g' | sed 's/name://g' | sed 's/ //g' | sort | grep -v ^$ | tail +3 | grep -v chi-backup | tr '[:upper:]' '[:lower:]' > $tmpclients
show name
print type:NSR client
EOF
#
if [ $(grep -c $client $tmpclients) -eq 0 ]; then
echo "Client name $client not found, Purge aborted " > $tmpmessage
cat $tmpclients >> $tmpmessage
display_message W
exit 68
fi
echo "Displaying Media Database to verify "
mminfo -ot -q"client=$client" -r'volume,ssid,client,savetime(17),name' | more
echo " "
echo "Are you sure you want to delete client $client"
echo "and all reference to the backup media ? "
echo "Reply y or n"
read yesorno
if [ $(echo ${yesorno:-n} | tr -s '[:upper:]' '[:lower:]') = 'y' ]; then
:
else
echo "Aborting purge -- No changes Made"
exit 1
fi
echo "$(date +%m/%d/%y) $(date +%H:%M:%S) $(basename $0) Started for client $client " >> $nsrlog
#
echo "Begin purge of the Media database for client $client"
for I in $(mminfo -ot -q"client=$client" -r'volume,ssid,client' | awk {'print $2'} ); do
echo "nsrmm -d -y -S $I "
nsrmm -d -y -S $I
if [ $? -ne 0 ]; then
sleep 5
nsrmm -d -y -S $I
if [ $? -ne 0 ]; then
sleep 5
nsrmm -d -y -S $I
fi
fi
done
#
if [ $(mminfo -ot -q"client=$client" 2>/dev/null | wc -l) -eq 0 ]; then
echo "Begin process of deleting the Client $client from the resource database"
else
echo "$client still has Media database entries " > $tmpmessage
echo "Please restart delete process " >> $tmpmessage
display_message W
exit 67
fi
#
while [ ${nsradminrc:-0} -eq 0 ]; do
echo "Deleting Client Resource $client "
nsradmin -i - <<EOF
delete type:NSR client;name:$client
EOF
nsradminrc=$?
echo $nsradminrc
done
#
echo "Deleting Client file Index for $client "
find /nsr/index/$client -type f -exec rm {} \;
find /nsr/index/$client -type d -depth -exec rmdir {} \;
#
# Clean up temp files
find /tmp -name "$(basename $0)*" -type f -exec rm {} \;
echo "$(date +%m/%d/%y) $(date +%H:%M:%S) $(basename $0) Ended " >> $nsrlog
exit 0
Ed Skolnik