< 1> #! /bin/bash < 2> < 3> # /etc/cron.daily/fmirror < 4> # < 5> # run the scheduled fmirror jobs. < 6> # < 7> # Author: Craig Sanders< 8> # < 9> # Copyright status: This script is copyright and licensed under the <10> # terms of the GNU General Public License. <11> # <12> # Revision History: <13> # v0.1: Dec 1997 <14> # - first version, not released to public. various config values were <15> # hard-coded into the script. <16> # v0.2 1998-01-10 <17> # - modified to use /etc/fmirror/config for all user-changeable <18> # configuration values (JOBS, NUMLOGS, and RUN_IN_BACKGROUND) <19> # v0.3 1998-01-10 <20> # - added support for daily and weekly jobs <21> # - added lots of helpful comments in the config file <22> # v0.4 1998-03-15 <23> # - used tempfile to get a tempory file for security reasons. <24> <25> #set -x <26> <27> confdir=/etc/fmirror <28> logdir=/var/log/fmirror <29> <30> # if logdir doesn't exist then create it. <31> [ -d $logdir ] || mkdir -p $logdir <32> <33> # read in the config file <34> . $confdir/config <35> <36> # allow command line override of which jobs to run <37> if [ -n "$1" ] ; then <38> MIRRORS="$@" <39> else <40> MIRRORS=$JOBS <41> fi <42> <43> # strip off .conf in case the user has ignored the instructions in <44> # /etc/fmirror/config saying to list only the base name. <45> MIRRORS=$(echo $MIRRORS | sed -e 's/\.conf//') <46> <47> do_it() { <48> run=/var/run/fmirror.$1 <49> if [ ! -e $run ] ; then <50> touch $run <51> tmpfile=`tempfile --name /tmp/fmirror.log.$1.$$.$(date +%s)` <52> LOG=$logdir/$1.log <53> <54> ( <55> [ -e $LOG ] && savelog -c $NUMLOGS $LOG <56> <57> # run the mirror job <58> rm -f ls-lR ls-lR.gz <59> conf="$confdir/$1.conf" <60> fmirror -f $conf >/dev/null <61> <62> # create the local ls-lR.gz file <63> localdir=`grep -i "^localdir:" $conf | cut -f2` <64> cd $localdir <65> # use full path to ls, just in case it is aliased to 'ls -F' or <66> # something. <67> /bin/ls -lR >ls-lR <68> gzip -9f ls-lR <69> ) >$tmpfile 2>&1 <70> <71> if [ -n "$MAILTO" ] ; then <72> cat $tmpfile | mail $MAILTO <73> fi <74> <75> rm -f $run <76> mv $tmpfile $LOG <77> fi <78> } <79> <80> for i in $MIRRORS ; do <81> if [ "$RUN_IN_BACKGROUND" = "1" ] ; then <82> do_it $i & <83> else <84> do_it $i <85> fi <86> done <87>