#!/bin/sh
#
#  g_top15a
#
#  Usage:  g_top15a
#
#  By: Angel Corbera, TSID1, Refinery Isla, Curacao, N.A
#  Comments to:  corbera@rocketmail.com
#
#  Purpose:  Get the 15 processes that have taken more CPU time.
#
REL=`uname -r`
case $REL in
   4.1.1 )   ps -ax > tmp1;;
   5.2   )   /usr/ucb/ps -ax > tmp1;;
   5.4   )   /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 %s %s\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 -20 tmp1 >> tmp2
else
  # 20 station:
  awk ' 
    $5~/[0-9][0-9]:[0-9][0-9]:[0-9][0-9]/ {printf "%0s\t%0s\t%0s\n",$2,$7,$8}
    $5 ~ /[A-Z][a-z][a-z]/ {printf "%0s\t%0s\t%0s\n",$2,$8,$9}
      ' tmp1 > tmp2
  sort -r -n +1 -2 tmp2 > tmp1
  echo "PID\tTIME\tPROCESS" > tmp2
  head -15 tmp1 >> tmp2
fi
more tmp2
rm tmp1 tmp2 > /dev/null 2>&1
1