#!/bin/sh
#
# ipcs: Sun Enterprise Server check - BB external script test
#
# version 1.0
# version 1.1 - modified for new conditions
# version 1.2 - properly uses $CAT instead of cat
# version 1.3 - properly uses $MACHINE instead of `uname -n` in bb-hosts check
# version 1.4 - properly uses $THIS_HOST instead of $MACHINE due to fqdn using comma in name - thanks Craig Cook#
# BIG BROTHER / XXXXXXXXXXXXXXXX status
#
# Written by Paul A. Luzzi
#  on March 22, 2000
#

########################################
# NOTE
# This has been tested with BB 1.2b, 1.4h2, 1.5, 1.5a
# 
# Tested on 
#   Sun Ultra 60, E220R/420R, E250/450, E3000/3500, E4500
#   AIX 43P
#   UnixWare 7
#   RedHat 5.2, 6.0 and 6.1
#   Linux Turbo Cluster Server 4.0
#   Caldera Open Linux 1.1 and 2.3
########################################

########################################
# INSTALLATION
#  step 1  - update the EXT section of the runbb.sh script to include this
#  ...
########################################

##################################
# CONFIGURE IT HERE
##################################

##################################
# Start of script
##################################

if test ! "$BBHOME"
then
	echo "template: BBHOME is not set"
	exit 1
fi

if test ! -d "$BBHOME"
then
	echo "template: BBHOME is invalid"
	exit 1
fi

if test ! "$BBTMP"                      # GET DEFINITIONS IF NEEDED
then
	echo "template: The BB environment is not set"
	exit 1
fi

#####
#####  Start of custom section added by Paul A. Luzzi
#####

#####
#####  Get Status proc - used to get all responses
#####
get_status() 
{

  #####
  #####  Setup any and all variables before beginning.
  #####

  #####
  #####    Modified extensively on 03-22-2000 by Paul A. Luzzi
  #####    for use with Big Brother
  #####
  #####  Purpose is to report back to a central server, all "standard"
  #####    detailed information about network, disk, volume, cpu, memory
  #####    which is not reported thru regular "easy" checks.
  #####
  #####  Any problem areas should be highlighted in :
  #####    bold, italics, and red font.
  #####

  #####
  #####  Setup some variables for use later
  #####
  COLOR="clear"
  
  #####
  #####  Verify Shared Memory Segments in Physical Memory
  #####
  echo "<P><DIV ALIGN=\"CENTER\"><HR>" 
  ##echo "<B>============== CPU Info ==============</B>"
  echo "<B> ===============================================================</B>"
  echo "<B>     Note : A value of 0 in the NATTCH field indicates that the </B>" 
  echo "<B>       segment can be removed with the ipcrm -m #.              </B>"
  echo "<B> ===============================================================</B>"
  echo "<B>--- (ipcs -a) ---</B>"
  echo "<HR></DIV>" 
  echo "<BLOCKQUOTE>" 
  CATCH_COMMAND=` $IPCS -a `
  echo "$CATCH_COMMAND"
  echo "</BLOCKQUOTE>" 

  #####
  #####  Make sure to export COLOR so that it gets back to "central"
  #####
  export COLOR

#####
#####  End of get_status proc
#####
}

#####
#####  Main body
#####
touch /tmp/$THIS_HOST.ipcs
$GREP $THIS_HOST $BBHOSTS | $GREP "ipcs" | 
while read line
  do
    if [ ! -z "$line" ]
      then
        echo "<BR><DIV ALIGN=\"CENTER\"><HR></DIV>" > /tmp/$THIS_HOST.ipcs
        echo "Status of interprocess communications on $THIS_HOST " >> /tmp/$THIS_HOST.ipcs
        echo "Captured : `$DATE` " >> /tmp/$THIS_HOST.ipcs
        get_status >> /tmp/$THIS_HOST.ipcs
        $BB $BBDISP "status $THIS_HOST.ipcs $COLOR `$DATE` `$CAT /tmp/$THIS_HOST.ipcs` "
      else
        COLOR="clear"
        $BB $BBDISP "status $THIS_HOST.ipcs $COLOR `$DATE` `$CAT /tmp/$THIS_HOST.ipcs` "
      fi
    done

#####
#####  End of custom section added by Paul A. Luzzi
#####
  
##############################################
# end of script
##############################################
