Personal tools
You are here: Home Members zopeadmin scripts mirrorSLC.sh
Document Actions

mirrorSLC.sh

script to automate SLC30X mirroring

Click here to get the file

Size 2.3 kB - File type text/x-sh

File contents

#!/bin/sh
#
# script to synchronize remote repositories from linuxsoft.cern.ch
# Author: Alexey Filin

# message about failure
mess=""

# mirror directory
mirror_dir="/opt"

# mirror host name
mirror_host=`hostname`

# repository host name
repository_host="linuxsoft.cern.ch"

# mail address to send message on failure
admin_address="root@localhost"

# log file to dump stdout and stderr
logfile="/var/log/mirrorSLC.log"

# exit code of failed command
exit_code=0


function mailAboutFailure {
    if [ "${mess}" != "" ]; then
	mail -s "ERROR: ${mirror_host}: failed to mirror SLC repository"\
	    "${admin_address}" <<EOF
${mess}
EOF
    fi
}

#############################################################################
# check and set environment

# redirrect stdin/stdout to log file
exec >& ${logfile} || {
    exit_code=$?
    mess="\`exec >& ${logfile}' failed"
    mailAboutFailure
    exit ${exit_code}
}

comm="cd ${mirror_dir}"
${comm} || {
    exit_code=$?
    mess="\`${comm}' failed"
    mailAboutFailure
    exit ${exit_code}
}

comm="ping -c 3 -w 100 ${repository_host}"
${comm} || {
    exit_code=$?
    mess="\`${comm}' failed"
    mailAboutFailure
    exit ${exit_code}
}

#############################################################################
# mirror repositories

# /cern/slc30X/i386
dl="apt/base\
    docs\
    dosutils\
    extras/RPMS\
    images\
    isolinux\
    kernel26/RPMS\
    LICENSE\
    README\
    RELEASE-NOTES.html\
    RPM-GPG-KEYs\
    SL\
    updates/RPMS\
    updates/testing/RPMS\
    updates/testing/RPMSonhold\
    yum"

for i in ${dl}; do
    comm="wget -r -N ftp://${repository_host}/cern/slc30X/i386/${i}"
    ${comm} || {
	exit_code=$?
	mess="${mess}
\`${comm}' failed"
    }
done

# /dag/redhat/el3/en/i386
dl="RPMS.dag\
    base"

for i in ${dl}; do
    comm="wget -r -N ftp://${repository_host}/dag/redhat/el3/en/i386/${i}"
    ${comm} || {
	exit_code=$?
	mess="${mess}
\`${comm}' failed"
    }
done

#############################################################################
# save log file and mail admin about failure

if [ ${exit_code} -ne 0 ]; then
    mailAboutFailure
    suff=`date +%Y.%m.%d.%H:%M`
    sync
    comm="cp ${logfile} ${logfile}.${suff}"
    ${comm} || {
	mess="\`${comm}' failed"
	mailAboutFailure
    }
fi

exit ${exit_code}
by portal administrator last modified March 23, 2006 at 13:02

Powered by Plone, the Open Source Content Management System