#!/bin/bash

# Variables a renseigner
# Stockage des fichiers pour monitoring de tous les users (pour l instant sur p86caub)
export MONIT_DIR=/ccc/work/cont003/dods/public/MONIT_DIR
export DODS_MONIT=/ccc/work/cont003/dods/public/DODS_MONIT

testr=`LC_ALL=C date +"%Y%m%dT%H%M"`

####### Boucle sur les USER (on doit etre connecte comme USER)
echo "User" $USER

mkdir -p $MONIT_DIR/${USER}_SIMUS

# On lance le script qui donne l etat du traitement des donnees
./showPackProgress.sh -p

if [ -e ${MONIT_DIR}/monit_all_new.txt ]
then
    tail -1 ${MONIT_DIR}/monit_${USER}.txt >> ${MONIT_DIR}/monit_all_new.txt
else
    cp monit_header.txt ${MONIT_DIR}/monit_all_new.txt
    tail -1 ${MONIT_DIR}/monit_${USER}.txt >> ${MONIT_DIR}/monit_all_new.txt
fi

####### fin boucle sur les USER

datestr=`LC_ALL=C date +"%Y%m%dT%H%M"`
cp ${MONIT_DIR}/monit_all_new.txt ${MONIT_DIR}/monit_all_${datestr}.txt
mv ${MONIT_DIR}/monit_all_new.txt ${MONIT_DIR}/monit_all.txt 

#if [ -d ${MONIT_DIR}/${USER}_SIMUS ]
#then
#    rm -rf ${MONIT_DIR}/${USER}_SIMUS
#fi
#cp -rf ${USER}_SIMUS ${MONIT_DIR}/.

#if [ "x$DODS_MONIT" != "x" ]
#then
#    rm -rf $DODS_MONIT
#fi
cp -prf $MONIT_DIR/* ${DODS_MONIT}/.
chmod -R o+rX ${DODS_MONIT}
