Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

process management 1

Status
Not open for further replies.

GrahamBright

Programmer
Oct 31, 2003
65
AT
Hi all,

I'd like to write a simple efficent means to monitor a problematic process. I'm thinking along the following lines, but if anyone has suggestions or means to improve my script please let me know.

Thanks,
Graham.
#!/bin/ksh
#
ITSME=`basename $0` # to get the right one
LIB_DIR=${LIB_DIR:-/data/users/mmscadm/bin}
. ${LIB_DIR}/lib.sh

HOME="/opt/mmsc/scripts"
MONITOR="/data/users/mmscadm/scripts/ppe_control/ppe.pid"
log_start
touch $LOCK_FILE
rm $MONITOR
cd $HOME


#stop pped
cd $HOME
/opt/mmsc/scripts/ppe stop
sleep 10
#search for pped

PROCS=`ps -aef | grep pped|grep -v grep|cut -d " " -f 4 > $MONITOR`

if [ -s $MONITOR ] # test for file with bytes

then

PID=`cat $MONITOR`
kill $PID
fi

###########
#start pped#

cd $HOME
rm $MONITOR #remove any monitor file from old run

/opt/mmsc/scripts/ppe start

#verify pped has started correctly
PROCS=`ps -aef | grep pped|grep -v grep|cut -d " " -f 4 > $MONITOR`
if [ ! -s $MONITOR ] #test for empty file

then
echo "problem starting pped"
#email clients probabaly perl SMTP


fi
 
Graham: some confusions

the main Q is:
PROCS=`ps -aef | grep pped|grep -v grep|
cut -d " " -f 4 > $MONITOR`
read, what you are doing here.
ps pass it's output to grep, and grep to grep
the second grep pass it to cut,
and cut writes to $MONITOR

what's in PROC ?
why use files, nowaday we have gigs of memory.
the kill cmd need an option (the signal to send)
most of " are useless and confusing
cut get troubles, ps prints formatted output:

aaaaa 1234 blah blah
aaaaa 55 blah blah
aaaaa 29999 blah blah
so, what's the f4 in cut ?

use a modern and FASTER ps, let it do the job, have a look to
sys5r4 /usr/bin/ps and it's option -o
assuming you will the proc-id

PROC=abc
ID=`/usr/bin/ps -efoargs,pid|sed -ne "s/.*$PROC.* //p"`
will give in ID the pid's of all PROC IF found
so:
for id in $ID # nota the var ID is superfluous
==== OR
for id in `/usr/bin/ps -efoargs,pid|sed -ne "s/.*$PROC.* //p"`
do kill -signal $pid # see man kill
done

to send mail no need of perl:
echo "$mssg" | mailx -s subject usera,user2,user...
NOTA: here the " preserve blancs in mssg

amateurs use: grep|grep -v grep
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top