#!/bin/sh

#
# Change the DIR variable below to point to the full
# pathname of the directory where this script is and where 
# the test result log file is (see the README.1st file)
#
DIR=/home/prl/tpstat


#
# Change the variables below at your own risk!!
# (they should not have to be changed at all)
#
FILE=log
NCFTP=${DIR}/ncftpput
YEAR=`date +%y`
MONTH=`date +%m`
DAY=`date +%d`
HOURMINSEC=`date +%H.%M.%S`
TARGET="log.`hostname`.${YEAR}${MONTH}${DAY}-${HOURMINSEC}"
TARGETPATH="${DIR}/LOGS/${YEAR}/${MONTH}/${DAY}/${TARGET}"
USER=tpstatftp
PASSWORD=ghn41if3
FTPSERVER=ftp.ficora.ghn.se



if [ ! -x ${NCFTP} ] ; then
  NCFTP=`which ncftpput`
  if [ ! -x ${NCFTP} ] ; then
    echo "Sorry, can't find executable ${NCFTP}"
    echo "You must install ncftp for the uploads to work"
    exit 1
  fi
fi

if [ -f ${DIR}/${FILE} ]; then
  if [ ! -d ${DIR}/LOGS/${YEAR} ]; then
    mkdir ${DIR}/LOGS/${YEAR}
  fi
  if [ ! -d ${DIR}/LOGS/${YEAR}/${MONTH} ]; then
    mkdir ${DIR}/LOGS/${YEAR}/${MONTH}
  fi
  if [ ! -d ${DIR}/LOGS/${YEAR}/${MONTH}/${DAY} ]; then
    mkdir ${DIR}/LOGS/${YEAR}/${MONTH}/${DAY}
  fi
  mv -f ${DIR}/${FILE} ${TARGETPATH}
  ${NCFTP} -u ${USER} -p ${PASSWORD} ${FTPSERVER} . ${TARGETPATH} >> ${DIR}/ncftpput.log
fi


