http://wiki.dirvish.org/?DailyEmailScript
http://www.keithl.com/linuxbackup.html
http://www.dirvish.org/pipermail/dirvish/2006-January/000578.html
#!/bin/sh
#dirvish_delete_empty - script to clean up Dirvish vaults
#copyright 2006 Chris Dunning - chris at bluenoteweb.com
#if no argument given, print some useful information
if [ -z $1 ]
then
echo 'No argument given'
echo 'This script checks Dirvish branches for failed images and
deletes them.'
echo 'Usage: dirvish_delete_empty /bank/vault/'
exit
fi
#change directory to the given vault
cd $1
for i in `ls`
{
#don't check the "dirvish" directory
if [ $i = "dirvish" ]
then
break
fi
#don't check the "current" directory, it's just a symlink
if [ $i = "current" ]
then
break
fi
#print the name of the directory we're checking
echo $i
#see if there's a summary file - this will help avoid deleting
non-dirvish directories
if [ -f $i/summary ]
then
#look for the word "success" in the summary file
success=`grep success $i/summary`
#if the variable is empty (no "success" in the file) delete the image
if [ -n $success ]
then
echo 'bad image, need to delete it'
rm -rf $i
else
echo 'successful image, keep it around'
#update the $last variable. At the end of the loop, this should
be the most current successful image.
last=$i
fi
else
echo 'no summary file!'
fi
}
echo 'last directory checked was'
echo $last
rm current -f
ln -s $last current