#!/bin/ksh
typeset -u RUN_PRE_EVENT # Force to UPPERCASE
typeset -u RUN_STARTUP_EVENT # Force to UPPERCASE
typeset -u RUN_POST_EVENT # force to UPPERCASE
RUN_PRE_EVENT='N' # A 'Y' will execute, anything else will not
RUN_STARTUP_EVENT='Y' # A 'Y' will execute, anything else will not
RUN_POST_EVENT='Y' # A 'Y' will execute, anything else will not
LOGFILE="/tmp/proc_status.log"
[[ ! -s $LOGFILE ]] && touch $LOGFILE
SCRIPT_NAME=$(basename $0)
TTY=$(tty)
INTERVAL="1" # Seconds between sampling
JOBS=
####################################################
############# DEFINE FUNCTIONS HERE ################
####################################################
usage ()
{
echo "/n/n/t*****USAGE ERROR*****"
echo "/n/nUSAGE: $SCRIPT_NAME seconds process"
echo "/nWill monitor the specified process for the"
echo "specified number of seconds."
echo "/nUSAGE: $SCRIPT_NAME [-s|-S seconds] [-m|-M minutes]"
echo " [-h|-H hours] [-d|-D days] [-p|-P process]/n"
echo "/nWill monitor the specified process for number of"
echo "seconds specified within -s seconds, -m minutes,"
echo "-h hours and -d days. Any combination of command"
echo "switches can be used./n"
echo "/nEXAMPLE: $SCRIPT_NAME 300 dtcalc"
echo "/n/nEXAMPLE: $SCRIPT_NAME -m 5 -p dtcalc"
echo "/nBoth examples will monitor the dtcalc process"
echo "for 5 minutes. Can specify days, hours, minutes"
echo "and seconds, using -d, -h, -m and -s/n/n"
}
####################################################
trap_exit ()
{
# set -x # Uncommant to debug this function
# Log an ending time for process monitoring
echo "INTERRUPT: Program Received an Interrupt...EXITING..." > $TTY
echo "INTERRUPT: Program Received an Interrupt...EXITING..." >> $LOGFILE
TIMESTAMP=$(date +%D@%T) # Get a new time stamp...
echo "MON_STOPPED: Monitoring for $PROCESS ended ==> $TIMESTAMP/n" /
>> $TTY
echo "MON_STOPPED: Monitoring for $PROCESS ended ==> $TIMESTAMP/n" /
>> $LOGFILE
echo "LOGFILE: All Events are Logged ==> $LOGFILE /n" > $TTY
# Kill all functions
JOBS=$(jobs -p)
if [[ ! -z $JOBS && $JOBS != '' && $JOBS != '0' ]]
then
kill $(jobs -p) 2>/dev/null 1>&2
fi
return 2
}
####################################################
pre_event_script ()
{
# Put anything that you want to execute BEFORE the
# monitored process STARTS in this function
: # No-OP - Needed as a place holder for an empty function
# Comment Out the Above colon, ':'
PRE_RC=$?
return $PRE_RC
}
####################################################
startup_event_script ()
{
# Put anything that you want to execute WHEN, or AS, the
# monitored process STARTS in this function
: # No-OP - Needed as a place holder for an empty function
# Comment Out the Above colon, ':'
STARTUP_RC=$?
return $STARTUP_RC
}
####################################################
post_event_script ()
{
# Put anything that you want to execute AFTER the
# monitored process ENDS in this function
: # No-OP - Need as a place holder for an empty function
# Comment Out the Above colon, ':'
POST_RC=$?
return $POST_RC
}
#####