#!/bin/sh - # $Header: /afs/linux.ibm.com/src/afs/@cell/scripts/cron_sync_CellServDB/RCS/cron_sync_CellServDB,v 1.7 2002/06/20 12:04:48 mpb Exp $ # $Locker: $ # # NAME cron_sync_CellServDB # # PURPOSE Update local CellServDB file and update AFS kernel sitelist # Write stderr and stdout to /var/log/cron_sync_CellServDB # # This provides a convenient way to keep multiple AFS client # machines with consistent /usr/vice/etc/CellServDB files # by keeping in sync with a "master" CellServDB in: # /afs/@cell/common/CellServDB # # USAGE Typically run by daily root cron job eg: # # 0 3 * * * /usr/local/scripts/cron_sync_CellServDB # # NOTE "@cell" is a symbolic link to /afs/$(cat /usr/vice/etc/ThisCell) # # http://www.angelfire.com/hi/plutonic/afs-faq.html#sub3.24 # # SPECIAL NOTE # This script contains a remarkable sed script. Enjoy! # # HISTORY # # 2002-06-14 Paul Blackburn adapted for crontab use # # 12-15-95: George Cebulka, george@ece.cmu.edu # added test to see if this is an OS conversion. # # 22 October 1993 Anton Knaus (awk@ece.cmu.edu) # Created. # let's get defensive... PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/afsws/bin IFS=" " unset ENV export NSORDER=bind # enough defensiveness! cmd=$(basename ${0}) src=/afs/@cell/common/CellServDB dst=/usr/vice/etc/CellServDB log=/var/log/${cmd} # ---------------------------------------------------------------- # functions # ---------------------------------------------------------------- usage () { cat <&2 exit 1 } error() { echo "${cmd} error: ${1}" >&2 } warning() { echo "${cmd} warning: ${1}" >&2 } tstamp() { echo "`date '+''%H''%M'':%S'` ${cmd}: ${1}" } doit() { tstamp "${1}" eval ${1} retcode=$? if [ ${retcode} != 0 ]; then error "\$?=${retcode}" fi } newCellServDB() { # # Build fs commands and pipe through shell # for execution. # sed -e ' s/>\([^ ]*\).*/fs newcell -name \1 -servers/ :again N; />/{ P; D; } s/\n\([^ ]*\).*/ \1/; s/\n/ /; ${ P; D; } b again ' ${CellServDB} | /bin/sh -x doit "fs checkvolumes" } # end function newCellServDB # ------------------------------------------------------------------- # main # ------------------------------------------------------------------- verbose="false" CellServDB=/usr/vice/etc/CellServDB # crack command line arguments while [ ! -z "${1}" ]; do case ${1} in -help | --help | -? | --usage | -usage ) usage exit ;; -verbose ) verbose="true" ;; -CellServDB ) shift if [ -z "${1}" ]; then fatal "missing CellServDB file name" else CellServDB=${1} fi ;; *) warning "unknown command line argument: ${1}" usage exit 1 ;; esac shift done mkdir -p /var/log 2>/dev/null # ensure /var/log exists if [ "${verbose}" = "true" ]; then echo "stdout and stderr now being written to ${log}" fi exec 4>&2 exec 3>&1 exec 1>${log} exec 2>&1 tstamp "commenced on $(date '+%a %d %h %y')" # sanity checking starts here case $(uname) in OSF | AIX | Linux) GQ=-q ;; ULTRIX) GQ=-s ;; esac df | grep -q "AFS" if [ $? != 0 ]; then fatal "AFS is not installed. Bye! ~~" fi if [ ! -f "${CellServDB}" ]; then fatal "missing local CellServDB file: ${CellServDB}" fi if [ ! -f "${src}" ]; then fatal "missing master CellServDB file: ${src}" fi x=$(whoami) if [ "${x}" != 'root' ]; then fatal "You must be logged in as root to run ${cmd}" fi # end of sanity checking # ------------------------------------------------------------------ if [ -s ${src} ]; then if [ ${src} -nt ${dst} ]; then tstamp "cp $dst ${dst}- && cp $src $dst && newCellServDB" cp $dst ${dst}- && cp $src $dst && newCellServDB else tstamp "master copy no newer: no processing to be done" fi else tstamp "warning: zero length file: ${src}" fi if [ "${verbose}" = "true" ]; then if [ -f ${dst}- ]; then doit "diff ${dst}- ${dst}" fi tstamp "completed" # Switch stdout and stderr back to report results exec 1>&3 exec 2>&4 doit "diff ${dst}- ${dst}" tstamp "completed" fi