Sponsored Content
Top Forums Shell Programming and Scripting Utilities not dying after script run Post 302770786 by Marc G on Monday 18th of February 2013 10:52:17 AM
Old 02-18-2013
Utilities not dying after script run

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:
Code:
#!/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:
Code:
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
 

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to manage multiple versions of a set of shell and SQL script utilities

Hi all --- I have the need to manage multiple versions of a set of utility scripts -- both shell and SQL and other .dat files. I am wondering if anyone out there knows of a good way to "PATH" to SQL and text files in a way similar to how PATH facilitates finding executables in a pre-specified... (2 Replies)
Discussion started by: DennisB
2 Replies

2. Ubuntu

Internet dying in Debian?

For some reason after a while my internet connection dies. I just moved on to Debian from Ubuntu and I can't find the dhclient-program to reconfigure dhcp. Pretty new to *nix's. ONe thing I noticed while rebooting (do get my connection back) is that it configures dhcp and says: reconfigure (or... (1 Reply)
Discussion started by: riwa
1 Replies

3. UNIX for Dummies Questions & Answers

how to run utilities

I have utilities installed on a UNIX platform and was wondering how i run them. (1 Reply)
Discussion started by: hershey101
1 Replies

4. IP Networking

network connection dying after an uptime of a day or two days

hie guys I am running fedora 6 on remote machines which are connecting to my server. The remote machines connect through one machine (more like my router) to the server. The problem i am having is that the remote machines are suppose to be reporting in real time mode to the server. Most of these... (2 Replies)
Discussion started by: no3more
2 Replies

5. Programming

Java application dying randomly

Hi, (First post, please be gental!) I have a java app that I am running on unix (centos) But it keeps dying randomly. The times seem random from anything between 3 hours and 3 days. I have a cronjob running to restart it when ever it dies but I would rather this happened less often. ... (2 Replies)
Discussion started by: sm9ai
2 Replies

6. Shell Programming and Scripting

Expect script cronjob running but dying prematurely

I have an Ubuntu machine that I'd like to update automatically. I've written an expect script to run the aptitude package manager and update my packages. Essentially it does: aptitude update && aptitude upgrade while answering "yes" at the appropriate time. It works quite nicely when run... (4 Replies)
Discussion started by: CluelessPerson
4 Replies

7. Red Hat

Snmpd dying on centos7.1

Hello All, SNMPD dying after 2 mins once it started. Here is the configuration Oct 12 04:43:00 localhost systemd: Starting Simple Network Management Protocol (SNMP) Daemon.... Oct 12 04:43:00 localhost snmpd: dlopen failed: /usr/lib64/libcmaX64.so: cannot open shared object file: No such... (1 Reply)
Discussion started by: shekar777
1 Replies

8. What is on Your Mind?

Are the BSDs dying?

Source a quick google search making clear that this isn't really new, and if we look at our bsd Forum we see that its the only operation systems forum with the last comment dated to June last year, whereas all the others have more recent comments. One comment dated to 2014 is exactly what I... (10 Replies)
Discussion started by: dodona
10 Replies
All times are GMT -4. The time now is 04:29 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy