#!/bin/sh
#
#   chk_awp          (Version 2.1, Feb99)
#
#  Usage:   chk_awp
#
#  By:  Angel Corbera, TSID1, Refinery Isla, Curacao, N.A.
#  Comments to:  corbera@rocketmail.com
#
# Purpose:  Get vital signs from an AP/WP/AW (20/50/51) stations.
#
# Previous version of this script was named "checkit" (Oct96).  
# New Changes:
# - Identify station type and run the required commands.
# - It does not require "top" program any more.
# - By default this script will DELETE any core files found.
#   If you prefer to keep those files for further analysis,
#   just add "#" in front of lines required (...)
# - It will try to create dir /opt/ac (50/51) or /usr/ac (20).
#
#
#
# What type of station is this one?
# Station Types included: 
#    Venix:   AP20 (303) 
#    Solaris: AP51 (308), AW51 (309), WP51 (409)
#    SunOS:   AP50 (304), AW50 (306), WP50 (406)
# Solaris versions:  51 = Solaris 2.2;  51B/C = Solaris 2.4
# Solaris 2.5.1 runs on ALL 50/51 stations if I/A is 4.3 or 6.1
#
STATION=`uname -n`
echo "\nThis script will check several points on this station: $STATION"
echo "Recommended usage to capture output: chk_awp
  chk_awp | tee $STATION.chk"
echo "File $STATION.chk will have all messages sent to screen."
echo "\nDo you want to continue? (y/n)"
read answer
if [ $answer != "y" ]
then
  echo "... exiting. Bye"
  exit
fi
NUM=`grep $STATION /usr/fox/sp/hldb | awk '{print $2}'`
case $NUM in
   303 )  TYPE="AP"; SERIES="20";;
   304 )  TYPE="AP"; SERIES="50";;
   306 )  TYPE="AW"; SERIES="50";;
   308 )  TYPE="AP"; SERIES="51";;
   309 )  TYPE="AW"; SERIES="51";;
   406 )  TYPE="WP"; SERIES="50";;
   409 )  TYPE="WP"; SERIES="51";;
esac
#
# Software Releases:  
#   "SVr2.2.1" (Venix), "4.1.1" (SunOS),
#   "5.2" (Solaris 2.2), "5.4" (Solaris 2.4)
#   "5.5.1" (Solaris 2.5.1)
#
REL=`uname -r`
#
# Choose echo command and chk/create dirs :
if [ $SERIES = "50" ]
then
   zecho="/usr/5bin/echo"
   if [ ! -d /opt/ac ]
   then
      mkdir /opt/ac
      cd /opt/ac
   fi
else
   zecho="echo"
   if [ ! -d /usr/ac ]
   then
      mkdir /usr/ac
      cd /usr/ac
   fi
fi
# 
$zecho "\n\tVITAL SIGNS REPORT FOR : $STATION ($TYPE$SERIES, $REL)\n"
$zecho "Valid for  : `date`\n"
# Note:  Enter your name on next line:
$zecho "Prepared by: Angel Corbera \n"
$zecho "-----------------------------------------------------------"
$zecho "1)  $STATION - LAST BACKUP DATES:\n"
if [ $SERIES = "20" ]
then
   $zecho "Data not available for this station"
else
   cat /etc/dumpdates
fi
 
$zecho "\n2) $STATION - FREE HD SPACE: (Capacity = %used) \n"
case $SERIES in
   20 )  df -t;;
   50 )  /bin/df;;
   51 )  $zecho "Filesystem       used    avail    free   %used    Mounted on\n"
         df -k | grep dsk;;
esac
 
$zecho "\n3) $STATION - MIRRORING STATUS:"
# Valid only for APs and AWs.
if [ $TYPE != "WP" ]
then
   if [ $SERIES = "20" ]
   then
      tail -15 /usr/adm/Mirror_Status
   else
      /usr/local/medusa/dft_show_status
   fi
else
   echo "Not applicable for this station"
fi
 
$zecho "\n-----------------------------------------------------------"
$zecho "4) $STATION - UPTIME & LOAD (last 1,5,15 minutes):\n"
if [ $SERIES = "20" ]
then
   who -b
else
   uptime
fi
 
$zecho "\n5) $STATION - TOTAL RUNNING PROCESSES : "
if [ $SERIES = "50" ]
then
   ps -ax | wc -l
else
   ps -ef | wc -l
fi
 
$zecho "\n6) $STATION - TOP 15 PROCESSES (THAT CONSUMED MORE CPU TIME) :\n "
case $REL in
   4.1.1 )      ps -ax > tmp1;;
   5.2   )      /usr/ucb/ps -ax > tmp1;;
   5.4   )      /usr/ucb/ps -ax > tmp1;;
   5.5.1 )      /usr/ucb/ps -ax > tmp1;;
   SVr2.2.1 )   ps -ef > tmp1;;
esac
if [ $REL != "SVr2.2.1" ]
then
  # 50/51 station:
  awk '
    {printf " %0s\t%0s\t%0s %0s %0s %0s %0s\n",$4,$1,$5,$6,$7,$8,$9}
      ' tmp1 > tmp2
  grep -v COMMAND tmp2 | sort -r -n +0 -1 > tmp1
  echo " TTIME\tPID\tPROCESS" > tmp2
  head -15 tmp1 >> tmp2
else
  # 20 station:
  awk '
    $5~/[0-9][0-9]:[0-9][0-9]:[0-9][0-9]/ {printf "\t%0s\t%0s\t%0s\n",$7,$2,$8}
    $5 ~ /[A-Z][a-z][a-z]/ {printf "\t%0s\t%0s\t%0s\n",$8,$2,$9}
      ' tmp1 > tmp2
  sort -r -n +0 -1 tmp2 > tmp1
  echo "\tTTIME\tPID\tPROCESS" > tmp2
  head -15 tmp1 >> tmp2
fi
cat tmp2
rm tmp1 tmp2 > /dev/null 2>&1
 
$zecho "\n7) $STATION - VM,CPU, SYSTEM TABLES :\n"
#
# 50/51: Virtual Memory, Swapping, Paging, I/O, Faults, CPU load
if [ $SERIES != "20" ]
then
  /usr/ucb/vmstat 5 10
else
  $zecho "Data not available yet, for this station type"
fi
$zecho "\n"

# 50: System facts (SunOS 4.x only).
if [ $SERIES = "50" ]
then
  $zecho "Used/Total  ; First value should be < 90% Second value."
  /etc/pstat -T
fi

# 51B/C: System Activity Reporter
if [ $REL = "5.4" ] | [ $REL = "5.5.1" ] 
then
  # /usr/sbin/sar 6 10
  /usr/sbin/sar -v 5 1
fi

$zecho "\n8) $STATION - OM/RFS/IPC PARAMETERS : \n" 
if [ $SERIES != "20" ]
then
  /usr/local/show_params
else
  $zecho "Data not available yet, for this station type"
fi

$zecho "\n-----------------------------------------------------------"
$zecho "9) $STATION - CORE files (List and/or Remove) :\n"
if [ $SERIES = "20" ]
then
  find / -name core -print > tmp1
  if [ -s tmp1 ]
  then
     cat tmp1
     for x in `cat tmp1 | awk '{print $NF}'`
     do
        rm $x
     done
  fi
else
  find / -fstype urfs -prune -o -name core -ls > tmp1
  if [ -s tmp1 ]
  then
     cat tmp1
     for x in `cat tmp1 | awk '{print $NF}'`
     do
       rm $x
     done
  fi
fi
 
$zecho "\n10) $STATION - BIG (>400K) FILES  :\n"
if [ $SERIES = "20" ]
then
  mv /usr/ac/bigs /usr/ac/bigs.old
  find / -type f -a -size +800 -ls | grep -v proc | sort -r +6 -7 > /usr/ac/bigs
  $zecho "Big files list was saved to: /usr/ac/bigs . Check it!"
  $zecho "Last week = `wc -l /usr/ac/bigs.old|awk '{print $1}'` BIG files"
  $zecho "Today     = `wc -l /usr/ac/bigs|awk '{print $1}'` BIG files"
else
  mv /opt/ac/bigs /opt/ac/bigs.old
  find / -fstype urfs -prune -o -type f -a -size +800 -ls | grep -v proc | sort -r +6 -7 > /opt/ac/bigs
  $zecho "Big files list was saved to: /opt/ac/bigs . Check it!"
  $zecho "Last week = `wc -l /opt/ac/bigs.old|awk '{print $1}'` BIG files"
  $zecho "Today     = `wc -l /opt/ac/bigs|awk '{print $1}'` BIG files"
fi
 
$zecho "\n11) $STATION - CRASH FILES (/opt/crash or /usr/crash):\n"
case $SERIES in
  20 )  $zecho "Not applicable for this station";;
  50 )  if [ $TYPE = "WP" ]
        then
           ls -lrt /usr/crash/$STATION | grep -v minfree |grep -v total
        else
           ls -lrt /var/crash/$STATION | grep -v minfree |grep -v total
        fi;;
   51 ) ls -lrt /opt/crash/$STATION | grep -v minfree |grep -v total;;
esac
 
$zecho "\n12) $STATION - SysMon DUMP FILES:\n"
# Only for System Monitor Hosts (AP/AW).
if [ -d /usr/fox/sysmgm/softmgr/dump ]
then
  ls -l /usr/fox/sysmgm/softmgr/dump/??????.? 2> /dev/null
else
  $zecho "This station does not host a System Monitor"
fi
 
$zecho "\n13) $STATION - WASTEBASKET FILES:\n"
# For Solaris 2.4 and higher only.
if [ $REL = "5.4" ] | [ $REL = "5.5.1" ]
then
  ls -l /.wastebasket
else
  $zecho "Not applicable for this station"
fi
 
$zecho "\n14) $STATION - USER/SYSTEM LOGIN HISTORY FILES:\n"
$zecho " To shrink them, read HH736, HH739, HH781."
$zecho "(cd /var/adm; cp /dev/null wtmpx; cp /dev/null utmpx)" 
case $SERIES in
  20 )  $zecho "Data not available yet, for this station type";;
  50 )  ls -l /var/adm/wtmp 2> /dev/null;;
  51 )  ls -l /var/adm/?tmp*;;
esac
 
$zecho "\n15) $STATION - cron LOG FILE:\n"
$zecho " To shrink it, read 4.0 Operational Recommendations, 10.16"
case $SERIES in
  20 )  ls -l /usr/lib/cron/log;;
  50 )  ls -l /var/log/syslog;;
  51 )  ls -l /var/cron/log;;
esac
rm tmp1 tmp2 > /dev/null 2>&1

1