#!/bin/sh

set -x

cd $DATA

try=0
doscp=NO

while [ $try -lt $ntrymax ]
do
   /etc/ping $REMOTE_HOST 64 2
   pingerr=$?
   if [ $pingerr -eq 0 ]
   then
     doscp=YES
     try=$ntrymax
   else
     msg="Cannot Contact $REMOTE_HOST on try $try of $ntrymax"
     postmsg "$jlogfile" "$msg"
     let try=try+1 
   fi
done


if test "$doscp" = "YES"
then
  mkdir -m 775 -p ${LOCAL_DIR}
  scp ${REMOTE_HOST}:${REMOTE_DIR}/* ${LOCAL_DIR}/
else
   err_exit "Cannot Contact $REMOTE_HOST after $ntrymax try/tries"
fi

exit
