Hello there,
here is small shell script which I use to run from crontab and redirect
its output to sendmail to produce rather readable messages. Maybe it would
be useful for you too ;-)
Any suggestions are, surely, appreciated. I live under FreeBSD and in
particular wanna know if there is more portable way to increment a
variable under shell than 'expr'
Sincerely,
D.Marck [DM5020, DM268-RIPE, DM3-RIPN]
------------------------------------------------------------------------
*** Dmitry Morozovsky --- D.Marck --- Wild Woozle --- [EMAIL PROTECTED] ***
------------------------------------------------------------------------
#!/bin/sh
#
# rsync wrapper. requires awk. usable for calling from crontab like
#
# runrsync mirror.samba.org::sambawww /pub/wwwmirror/samba/ \
# --exclude=ftp 2>&1 | sendmail mirror-owner
#
# written by Dmitry Morozovsky (D.Marck) <[EMAIL PROTECTED]>
#
# $Id: runrsync.sh,v 1.3 2000/11/20 08:51:25 marck Exp $
#
RSYNC="/usr/local/bin/rsync"
OPTIONS="-rltv --delete"
# set appropriate umask to allow group writable directories and files
# comment out to disable
UMASK=002
# Max number of retries
MAXTRIES=50
# Sleep time between retries (seconds)
SLEEPTIME=15
if [ "X$2" = "X" ]; then
echo usage: $0 host::module dir [rsync flags]
exit 1
fi
echo "Subject: rsync mirror of $1 -> $2"
echo ""
date
FROM="$1"; shift
TO="$1"; shift
OPTIONS="${OPTIONS} $*"
[ "X${UMASK}" != "X" ] && umask ${UMASK}
# main loop
tries=0
while ${RSYNC} ${OPTIONS} "${FROM}" "${TO}" 2>&1 | awk '
# skip rsync server motd
BEGIN {printed=0}
$1 == "@ERROR:" { print; err=1 }
{
if ( $0 ~ /^receiving file list/ )
printed=1
if ( $1 == "readlink" && $NF == "denied" )
next
if ( printed )
print
}
END { exit !err }' ; do
tries=`expr ${tries} + 1`
if ${tries} -gt ${MAXTRIES}; then
echo "Too many tries. Aborting"
break
fi
echo "Sleeping for ${SLEEPTIME} seconds..."
sleep ${SLEEPTIME}
done
date
# end