ok, ok, ok, i get it. you all hate me. just joking.
how about this, can you guys look over my code and tell me if there is a better way to do it. i have it working, but i want to learn if there are better ways of doing what it does, ie simpler, as well as hone my abilities? it runs as a cronjob and the output is appended to a file in /tmp.
thanks for any help.
#!/usr/bin/ksh
##
## JWD 10/30/03
##
##
#### Setting Array for While Loop
####
set -A PROC `$ISQL << !
use config_db
go
select distinct PROCESS_NAME from PROCESSES
where BLOCK = 'n'
go
!`
#### Setting variable to count number of processes for loop
#### used for loop control
COUNT1=`$ISQL << !
use config_db
go
select distinct PROCESS_NAME from PROCESSES
where BLOCK = 'n'
go
!`
LOOP_NUM=$(( `echo $COUNT1 | awk '{print NF}` - 3 ))
#### Counting total number of processes
#### that should be running
COUNTALL_NORM=`$ISQL << !
use config_db
go
select count(PROCESS_NAME) from PROCESSES
where BLOCK = 'n'
go
!`
#### Comparing the total number of actual processes
#### to the number that should be running
function total_proc {
COUNTALL_ACT=`/usr/bin/ps -ef -o comm | grep netrac | wc -l`
echo $COUNTALL_ACT processes currently running.
CC=`echo $COUNTALL_NORM | awk '{ print $2 }`
echo
COUNTALL_DIFF=$(( $COUNTALL_ACT - $CC ))
if [ $COUNTALL_ACT -gt $CC ];
then
echo There are $COUNTALL_DIFF too many processes currently running.
echo;
fi
}
#### Comparing the number of individual processes
#### to the number that should be running
function proc_check {
COUNTIND_NORM=`$ISQL << !
use config_db
go
select count(PROCESS_NAME) from PROCESSES
where BLOCK = 'n' and PROCESS_NAME = '$PNAME'
go
!`
COUNTIND_ACT=`/usr/bin/ps -ef -o comm | grep netrac | grep $PNAME | wc -l`
COUNTIND_NORMA=`echo $COUNTIND_NORM | awk '{ print $2 }`
COUNTIND_DIFF=$(( $COUNTIND_ACT - $COUNTIND_NORMA ))
if [ $COUNTIND_ACT -gt $COUNTIND_NORMA ];
then
echo There are $COUNTIND_DIFF too many $PNAME processes currently running.
echo;
fi
}
/usr/bin/date
echo
total_proc
X=2
while (( $X < $LOOP_NUM ))
do
PNAME=${PROC[$X]}
proc_check
X=$(( $X + 1 ))
done