mirrorSLC4.sh
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/mirrorSLC4.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
# docs\
# dosutils\
# kernel26/RPMS\
# LICENSE\
# README\
# updates/testing/RPMSonhold\
# yum"
# /cern/slc4X/i386
dl="apt/base\
extras/RPMS\
images\
isolinux\
RELEASE-NOTES.html\
RPM-GPG-KEYs\
SL\
updates/RPMS\
updates/testing/RPMS"
for i in ${dl}; do
comm="wget -r -N ftp://${repository_host}/cern/slc4X/i386/${i}"
${comm} || {
exit_code=$?
mess="${mess}
\`${comm}' failed"
}
done
# /dag/redhat/el4/en/i386
dl="base\
dag/headers\
dag/repodata\
RPMS.dag"
for i in ${dl}; do
comm="wget -r -N ftp://${repository_host}/dag/redhat/el4/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}