Hi folks,
Friendly router geek wanting to be a programmer here...
So I worked with another guy here and came up with this to capture Unix admin data:
#!/bin/ksh
#
#
# Set Default Paths
#
PATH=/usr/apps/client/bin:$PATH; export PATH
LD_LIBRARY_PATH=/usr/apps/client/lib:$LD_LIBRARY_PATH; export LD_LIBRARY_PATH
NOSHOME=/usr/apps/client/bin; export NOSHOME
# Execute the NOS provided top program with CPU MEMORY and LOAD values to be extracted to temporary files
#
$NOSHOME/top -d1 -q | /usr/bin/head -n 5 | /usr/bin/grep CPU | /usr/bin/awk -F"," '{print $1}' | /usr/bin/awk -F":" '{print $2}' | /usr/bin/awk -F" " '{print $1}' > /tmp/cpu.out
$NOSHOME/top -d1 -q | /usr/bin/head -n 5 | /usr/bin/grep Memory | /usr/bin/awk -F"," '{print $1,$2}' | /usr/bin/awk -F":" '{print $2}' | /usr/bin/awk -F" " '{print $1","$4}' > /tmp/mem.out
$NOSHOME/top -d1 -q | /usr/bin/head -n 5 | /usr/bin/grep Memory | /usr/bin/awk -F"," '{print $3,$4}' | /usr/bin/awk -F" " '{print $1","$4}' > /tmp/swap.out
$NOSHOME/top -d1 -q | /usr/bin/head -n 5 | /usr/bin/grep load | /usr/bin/awk -F";" '{print $2}' | /usr/bin/awk -F":" '{print $2}' | /usr/bin/sed 's/^[ ]*//;s/[ ]*$//' > /tmp/loadavg.out
# Gather all data into single file and clean up
#
CPU=`cat /tmp/cpu.out`
MEM=`cat /tmp/mem.out`
SWAP=`cat /tmp/swap.out`
LOAD=`cat /tmp/loadavg.out`
HOST=`/usr/bin/hostname`
DAY=`/usr/bin/date +%b-%d-%y`
TIME=`/usr/bin/date +%H:%M:%S`
# Configure date values to figure out proper storage of comma delimited values
#
typeset -i MONTH=`/usr/bin/date +%m`
MONTH=$(echo "$MONTH" | tr ' ')
typeset -i DAY=`/usr/bin/date +%d`
DAY=$(echo "$DAY" | tr ' ')
typeset -i YEAR=`/usr/bin/date +%Y`
YEAR=$(echo "$YEAR" | tr ' ')
# Create a variable FILE to concat variables into a single variable to test against
FILE=$MONTH"-"$YEAR-$HOST".dat"
# Check to see if file is empty. If not, populate the values, otherwise create the needed file and populate
#
if [ -e $NOSHOME/../data/OSKPI/$FILE ]
then
echo $HOST","$DAY","$TIME","$CPU","$MEM","$SWAP","$LOAD >> $NOSHOME/../data/OSKPI/$MONTH-$YEAR-$HOST.dat
else
echo $HOST","$DAY","$TIME","$CPU","$MEM","$SWAP","$LOAD > $NOSHOME/../data/OSKPI/$MONTH-$YEAR-$HOST.dat
fi
# Remove all temporary files and exit
#
rm /tmp/cpu.out /tmp/mem.out /tmp/swap.out /tmp/loadavg.out
exit 0
But once the script runs, it leaves processes still running as shown:
bash-3.00$ ps -efa | grep -v wrapper | grep -v oracle | grep -v java
.
.
.
root 11153 11098 0 07:00:04 ? 0:00 /usr/bin/sed s/^[ ]*//;s/[ ]*$//
root 19606 479 0 00:14:49 ? 0:00 /usr/lib/ssh/sshd
root 11150 11098 0 07:00:04 ? 0:00 /usr/bin/grep load
root 11149 11098 0 07:00:04 ? 0:00 /usr/bin/head -n 5
root 11098 11097 0 07:00:00 ? 0:00 /bin/ksh /usr/apps/client/bin/gatherOSKPI.sh
root 11152 11098 0 07:00:04 ? 0:00 /usr/bin/awk -F: {print $2}
root 11097 287 0 07:00:00 ? 0:00 sh -c /usr/apps/client/bin/gatherOSKPI.sh
root 11146 11098 50 07:00:04 ? 1040:23 /usr/apps/client/bin/top -d1 -q
root 11151 11098 0 07:00:04 ? 0:00 /usr/bin/awk -F; {print $2}
-bash-3.00$
Can anyone explain why this is?
Thanks in advance