#! /bin/sh
#
#+
#
# NAME
# ====
#
# tlogd.sh -  shows the most recent release of ${IRCAAM_LOG}/action.log.YYYY-MM-DDTHH:MM:SSZ
#
# SYNOPSIS
# ========
#
# ::
#
#  $ tlogd.sh action
#
#
# DESCRIPTION
# ===========
#
# ``tlogd.sh`` shows the most recent release of ${IRCAAM_LOG}/action.log.YYYY-MM-DDTHH:MM:SSZ.
#
#
# SEE ALSO
# ========
#
# ircaam_profile.sh_
#
# .. _ircaam_profile.sh : ircaam_profile.sh.html
#
# dlogd.sh_
#
# .. _dlogd.sh : dlogd.sh.html
#
# elogd.sh_
#
# .. _elogd.sh : elogd.sh.html
#
# plogd.sh_
#
# .. _plogd.sh : plogd.sh.html
#
#
# FILES
# =====
#
# original location
# ~~~~~~~~~~~~~~~~~
#
# /usr/home/fplod/incas/ircaam/ircaam_ws/src/tlogd.sh sur cerbere.locean-ipsl.upmc.fr
#
# EVOLUTIONS
# ==========
#
# $Id$
#
# - fplod 2008-11-26T10:13:13Z aedon.locean-ipsl.upmc.fr (Darwin)
#
#   * replace PROJECT_LOG by IRCAAM_LOG
#
# - fplod 2008-03-18T09:15:57Z ajax.locean-ipsl.upmc.fr (Linux)
#
#   * replace FORVAN_LOG by PROJECT_LOG
#
# - fplod 2006-02-20T16:08:33Z aedon.lodyc.jussieu.fr (Darwin)
#
#   * posix
#
#-
#
set -u
system=$(uname)
case "${system}" in
AIX|IRIX64)
  echo " www : no specific posix checking"
;;
*)
  set -o posix
;;
esac
#
command=$(basename ${0})
#
if [ "${1}" = "" ]
then
 echo "${command} : eee : 1st parameter missing" >&2
 exit 1
fi
# check for ${IRCAAM_LOG} definition
if [ "${IRCAAM_LOG}" = "" ]
then
 echo " eee : \${IRCAAM_LOG} not defined"
 exit 1
fi
#
# check for ${IRCAAM_LOG} existence
if [ ! -d ${IRCAAM_LOG} ]
then
 echo " eee : ${IRCAAM_LOG} not found"
 exit 1
fi
#
# check for permission access on IRCAAM_LOG
if [ ! -x ${IRCAAM_LOG} ]
then
 echo " eee : ${IRCAAM_LOG} not reachable"
 exit 1
fi
#
log=$(find ${IRCAAM_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 ${IRCAAM_LOG}/${1}.log" >&2
  exit 1
 else
  more ${log}
  exit 0
 fi
else
 exit 1
fi
