#! /bin/sh
#+
#
# .. program:: tlogd.sh
#
# .. _tlogd.sh:
#
# =====================================================================================================
# tlogd.sh -- shows the most recent release of :file:`${PROJECT_LOG}/{action}.log.{YYYYMMDDTHHMMSSZ}`
# =====================================================================================================
#
# SYNOPSIS
# ========
#
# ::
#
#  $ tlogd.sh action
#
#
# DESCRIPTION
# ===========
#
# ``tlogd.sh`` shows the most recent release of :file:`${PROJECT_LOG}/{action}.log.{YYYYMMDDTHHMMSSZ}`
#
#
# SEE ALSO
# ========
#
# :ref:`project_profile.sh`
#
# :ref:`dlogd.sh`
#
# :ref:`elogd.sh`
#
# :ref:`plogd.sh`
#
# EVOLUTIONS
# ==========
#
# - fplod 20101213T150004Z aedon.locean-ipsl.upmc.fr (Darwin)
#
#   * creation
#
#-
#
set -u
system=$(uname)
case "${system}" in
   AIX|IRIX64)
      echo " www : no specific posix checking"
   ;;
   *)
      set -o posix
   ;;
esac
unset system
#
LANG=POSIX
#
command=$(basename ${0})
#
if [ "${1}" = "" ]
then
   echo "${command} : eee : 1st parameter missing" >&2
   exit 1
fi
# check for ${PROJECT_LOG} definition
if [ "${PROJECT_LOG}" = "" ]
then
   echo " eee : \${PROJECT_LOG} not defined"
   exit 1
fi
#
# check for ${PROJECT_LOG} existence
if [ ! -d ${PROJECT_LOG} ]
then
   echo " eee : ${PROJECT_LOG} not found"
   exit 1
fi
#
# check for permission access on PROJECT_LOG
if [ ! -x ${PROJECT_LOG} ]
then
   echo " eee : ${PROJECT_LOG} not reachable"
   exit 1
fi
#
log=$(find ${PROJECT_LOG} -name "${1}.log.????????T??????Z" 2> /dev/null | sort | \
tail -n 1)
tmp=${?}
if [ ${tmp} -eq 0 ]
then
   if [ "${log}" = "" ]
   then
      echo "${command} : eee : no release of ${PROJECT_LOG}/${1}.log" >&2
      exit 1
   else
      more ${log}
      exit 0
   fi
else
   exit 1
fi
