#!/bin/sh
#      ************************************************
#      *                                              *
#      *  Print Running IRIS (and Related) Processes  *
#      *                                              *
#      ************************************************
#
#           COPYRIGHT (c) 1994, 1999, 2004, 2010, 2012 BY
#            VAISALA INC., WESTFORD MASSACHUSETTS, U.S.A.
# 
# THIS SOFTWARE IS FURNISHED UNDER A LICENSE AND MAY BE USED AND  COPIED
# ONLY  IN  ACCORDANCE WITH  THE  TERMS  OF  SUCH  LICENSE  AND WITH THE
# INCLUSION OF THE ABOVE COPYRIGHT NOTICE.  THIS SOFTWARE  OR  ANY OTHER
# COPIES  THEREOF MAY NOT BE PROVIDED OR OTHERWISE MADE AVAILABLE TO ANY
# OTHER PERSON.  NO TITLE TO AND OWNERSHIP OF  THE  SOFTWARE  IS  HEREBY
# TRANSFERED.

TMP1=/tmp/$$_tmp1 ; TMP2=/tmp/$$_tmp2 ; rm -f ${TMP1} ${TMP2}

trap "rm -f ${TMP1} ${TMP2} ; exit" INT EXIT

echo "IRIS Activity on '`hostname`' at: `date`"

# Make machine-dependent assignments
#
MACHINE=`uname -s`

if [ "${MACHINE}" = 'Linux' ] ; then
  alias PSCMD="ps -ewo user,group,pid,ppid,nice,pri,%cpu,bsdtime,%mem,vsz,args"
else
  alias PSCMD="ps -eaf"
fi

# Make up a list of all processes that are running on the system.
# Remove long path names, and indent for later printing.  Also remove
# any line that contains "IRIS_BIN=", as these may crop up during
# invocations of ps_iris from the install_iris script.
#
PSCMD | sed 's#\/\/#\/#g' | sed "s.${IRIS_BIN}.." | sed "s.${IRIS_LIBEXEC_SERVICES}.." |
  sed "s/^/   /" | grep -E -v "IRIS_BIN=" > ${TMP1}

HEADER="`grep -E ' PID ' ${TMP1}`"

NEEDLF="false"

# Make up detached process list by searching for lines having "IRIS_" in them,
# but not "IRIS_ANT".
#
LIST="`grep -E 'IRIS_' ${TMP1}`"
if [ "${LIST}" != "" ] ; then
  if [ "${NEEDLF}" = "true" ] ; then echo "" ; fi ; NEEDLF="true"
  echo "Detached Processes:"
  echo "${HEADER}"
  echo "${LIST}"
fi

# Make up list of antenna processes
#
LIST="`grep -E ' ANT_' ${TMP1}`"
if [ "${LIST}" != "" ] ; then
  if [ "${NEEDLF}" = "true" ] ; then echo "" ; fi ; NEEDLF="true"
  echo "Antenna Processes:"
  echo "${HEADER}"
  echo "${LIST}"
fi

# Reduce the total process list by the ones printed so far, and then
# search for matches with any executables from the IRIS directories.
#
LOCALFILES="checkup_man make_license sigfbackup pruneincs struct_chk"
grep -E -v 'IRIS_' ${TMP1} | grep -E -v ' ANT_' | sed 's/$/ /' > ${TMP2}

BASE_BINS="AntExport AntLogToAscii AntLogger ant_logd ant_rcvd ant_xmtd antennax \
  antsim_rcvd antsim_xmtd antsimcheck antx ascope audio bitex color_file_dump color_setup \
  dspx dspx_scope errdiag hclass_config init_sigbru_dvd irisnet irisnetstat keys \
  makeAsciiSetups manuals nfl_to_overlay nr_noisefig nr_velcal overlay rtd_insert rtd_nids3_xmt \
  rtd_v1_xmt rtd_v2_xmt rtdisp setup setup_change_file shape_dump show_machine_code sigaudio \
  sigbru sigxbell start_antennad stop_antennad suncal utils zauto7 zcal zdrcal"

IRIS_BINS="ChDataType ChProductName ChangeTaskName PomHeader728 ProductToRegion Rain1GageCor \
  TapeInv723 archive beam_blockage change_raw clnt_recv copy_data_tape crab data_convert ingest \
  ingfio init_iris_dvd init_iris_lda init_iris_mo init_iris_tape input iris iris2nm iris_client_shell \
  iris_clnt_rcv iris_send_task iris_servers llwas_sim mode_change network output product productx \
  raw_create_task rays reingest rib_rcv rib_xmt ribbuild ribsetup rtd_echo runways sclient server \
  setup_change show_availability show_iris signal_iris sserver start_iris stop_iris tapex tdwr_llwas_int \
  tdwr_reading_task tdwr_sending_task tdwr_sim upi_rcv upi_xmt vribbon watchdog window"
  
RDA_BINS="dspexport tsarchexec bite_export dspmuxd ifdr_rpc_get_oss_licenses ifdr_rpc_update \
  ihexutil Inquiry jamplayer netflash pstr1163_tool rcp903_burnin rcp903_test rdadiags rdaport \
  rtnice rvp10proc rvp9proc rvpts_example rvpts_rcp903_typetest show_rda softplane test_asr_udp_type \
  tsarchive tsclientshell tsexport tsimport tsswitch tsview wsr98d_amuxIO_monitor wsr98d_test \
  wsr98d_typetest rcp8 rvp10 rvp9"

BINS=`echo "${BASE_BINS} ${IRIS_BINS} ${RDA_BINS}" | grep -E -v 'ps_iris|IRIS'`

NEEDHD="true"
for ITEM in ${LOCALFILES} ${BINS} ; do

  alias MATCHCMD="grep -E '[0-9] ${ITEM} |[0-9] [^ ]*/${ITEM} ' ${TMP2}"
  MATCH="`MATCHCMD`"

  if [ "${MATCH}" != "" ] ; then
    if [ "${NEEDLF}" = "true" ] ; then echo "" ; fi ; NEEDLF="false"
    if [ "${NEEDHD}" = "true" ] ; then
      echo "Stand-alone Utilities:"
      echo "${HEADER}"
      NEEDHD="false"
    fi
    echo "${MATCH}"
  fi

done
