
#!/bin/sh
# File	: get_own-planning.sh
# By	: Maarten.deBoer@Atos.net
# Subject	: SCript to get planning-data
#
PGM="`basename $0|cut -d\. -f1`"
VER="0.1"
TMP="/tmp/${PGM}.$$"
LOG="${HOME}/log/${PGM}"
SSH="/usr/bin/ssh -n"

REMHOST="aoxnlfsd01"
PLANDIR="${HOME}/data/own-planning"

echo "`date` ${PGM} v${VER} started (REMHOST=${REMHOST})."|tee -a ${LOG}

# Clean ${PLANDIR} first
rm -f ${PLANDIR}/*

${SSH} ${REMHOST} 'ls -1 /home' |while read USER
do
  ${SSH} ${REMHOST} "ls -1 /home/${USER}/.planning" | while read FILE
  do
    if [ "${FILE}" != "" ]; then
      scp ${REMHOST}:/home/${USER}/.planning/${FILE} ${PLANDIR}/${USER}_${FILE}
    fi
  done  # FILE
# If files in PLANDIR, then copied then get USER(name) info from the remote passwd-file
  cd ${PLANDIR}
  ANSW="`ls -1 ${USER}_*`"
  if [ "${ANSW}" != "" ]; then
    ${SSH} ${REMHOST} "grep ${USER} /etc/passwd" > ${PLANDIR}/${USER}_passwd-info
  fi

done  # USER

exit 0

