
#!/bin/ksh
set +x
#--------------------------------------------------------------------------#
# Name: copy_hosts_file.sh                                                 #
# Description: Script to copy ${HOME}/etc/hosts to /vol/vol0/etc of filers #
# Version: 1.1                                                             #
# References:                                                              #
# Documentation:                                                           #
# Parameters: none                                                         #
# Usage:  copy_hosts_file.sh                                               #
# Global Description:                                                      #
# Author(s): Atos                                                          #
# Change log:                                                              #
# aut   date            vers    comments                                   #
# RL    09-10-2012      1.0     Initial version by Richard Loos            #
# MdB	04-08-2014	1.1	Update with sudo
# MdB	14-12-2015	1.2	Changed filers_ibm to filers
#                                                                          #
#--------------------------------------------------------------------------#
#--------------------------------------------------------------------------#
# Initialize variabels                                                     #
#--------------------------------------------------------------------------#
VER="1.2"
HOME="/home/aodfm01a"
LOGDIR=${HOME}/log
LOGFILE=${LOGDIR}/copy_hosts_file.log
RUNDATE=$(date +%a)

#--------------------------------------------------------------------------#
# $LOGFILE should exist.                                                   #
#--------------------------------------------------------------------------#
if [ ! -f "${LOGFILE}" ]
then
   echo "`date +%Y%m%d_%H%M`: ${LOGFILE} doens't exist, create empty one"
   >${LOGFILE}
fi

#--------------------------------------------------------------------------#
# ${HOME}/etc/hosts should exist.                                                   #
#--------------------------------------------------------------------------#
if [ ! -f "${HOME}/etc/hosts" ]
then
   echo "`date +%Y%m%d_%H%M`: ${HOME}/etc/hosts doens't exist" | tee -a ${LOGFILE}
   exit 0
fi

#--------------------------------------------------------------------------#
# Save hosts file & copy to ~data/out dir, for copy to filers via `sudo`
#--------------------------------------------------------------------------#
cp ${HOME}/etc/hosts ${HOME}/etc/hosts_${RUNDATE}
cp ${HOME}/etc/hosts ${HOME}/data/out/hosts

#--------------------------------------------------------------------------#
# Start copy of hosts file to /vol0/etc of filers                          #
#--------------------------------------------------------------------------#
for FILER in $(cat ${HOME}/etc/filers)
do
  echo "`date +%Y%m%d_%H%M`: copy ${HOME}/etc/hosts to /filers/${FILER}/vol0/etc/hosts" | tee -a ${LOGFILE}
  sudo cp ${HOME}/data/out/hosts /filers/${FILER}/vol0/etc/hosts
done


