
#!/bin/ksh
# File  : copy_ssh_keys
# By    : MaartenDeBoer.nl, 100202
# Subject       : Copy SSH-authorizes_keys using ndmpcopy (caused by lack of NFS at filers)
set -x
PGM="`basename $0|cut -d\. -f1`"
LOG="${HOME}/log/${PGM}.log"

#FILERS="nlnaf02 nlnaf03 nlnaf04 hwnaf05 hwnaf06 nlnaf07 nlnaf09 nlnaf10 nlnaf11 nlnaf12 nlnaf13 nlnaf14 nlnaf15 nlnaf16 nlnaf17 nlnaf18 nlnaf19 nlnaf20 nlnaf21 nlnaf22 nlnaf23 nlnaf24 nlnaf25 nlnaf26 nlnaf51 nlnaf52 nlnaf53 nlnaf54"
FILERS="nlnaf25 nlnaf26"

USERS="nl24191"

#USER="`who am i| awk '{print $1}'`"
#mkdir ${HOME}/log

#mkdir -p /tmp/${USER}/.ssh
#cp ~${USER}/.ssh/id_dsa.pub /tmp/${USER}/.ssh/authorized_keys
#cd /tmp
#tar cvf ${USER}.tar ${USER}

SRC_FILER="nlnaf25"

SRC_PWD=`ssh ${SRC_FILER} ndmpd password ndmpd_user | awk '{print $2}'`
SRC_IP="`grep \"${SRC_FILER} \" /etc/hosts | grep -v ^# | awk '{print $1}'`"

for DEST_FILER in ${FILERS}
do
  for USER in ${USERS}
  do
    echo "`date` ${PGM}: ${USER}@${DEST_FILER} ..." | tee -a ${LOG}

  DEST_IP="`grep \"${DEST_FILER} \" /etc/hosts|grep -v ^# | awk '{print $1}'`"
  DEST_PWD=`ssh ${DEST_FILER} ndmpd password ndmpd_user | awk '{print $2}'`
# Copy SSH-key by using NDMPDCOPY
##  ssh ${DEST_FILER} ndmpcopy -sa ndmpd_user:${SRC_PWD} -da ndmpd_user:${DEST_PWD} ${SRC_IP}:/vol0/home/${USER}/.ssh/${USER} ${DEST_IP}:/vol/vol0/etc/sshd/${USER}
  ssh ${DEST_FILER} ndmpcopy -sa ndmpd_user:${SRC_PWD} -da ndmpd_user:${DEST_PWD} ${SRC_FILER}:/vol/vol0/home/${USER}/.ssh ${DEST_FILER}:/vol/vol0/etc/sshd/${USER}/.ssh

  done

done

exit

