![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| job/process scheduling or control | deiphon | Shell Programming and Scripting | 0 | 03-30-2008 07:37 PM |
| Control process from different terminal (over SSH) | rakeshou | UNIX for Advanced & Expert Users | 3 | 12-19-2007 08:48 PM |
| init and process control | dexfantasy | UNIX for Dummies Questions & Answers | 4 | 12-15-2006 10:45 PM |
| control the process | ust | UNIX for Advanced & Expert Users | 2 | 09-26-2005 12:28 AM |
| unix process control | nicko | Filesystems, Disks and Memory | 2 | 05-16-2002 08:39 AM |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
2 Questions about my process control script
Hi all, My tiny mind is struggling with the following script that shuts down Tomcat on Sol. 8 and kills any defunct processes Tomcat might leave behind (as it so often does). I realize that fixing Tomcat would be best, but this is a band-aid so I won't have to do as much off-hours support of this pig, which will hopefully buy me time to research the matter more thoroughly. Anyway, on to the goods... Code:
#!/bin/sh
# variables
tcpid=`ps -ef |grep java |grep -v grep |sort |awk '{print $2}'`
signal=9
tclog=/opt/local/jakarta/logs/catalina.out
now=`date +'%Y%m%d%H%M'`
# Shutdown Tomcat
/opt/local/jakarta/bin/shutdown.sh
sleep 20
if [ $tcpid != "" ]
do
(sudo kill $signal) $tcpid
sleep 5
else [ $tcpid = "" ]
echo "Java Stopped"
done
# manage catalina.out, cache dirs and core dumps
cp $tclog /opt/local/jakarta/logs/catalina.out.$now
>/opt/local/jakarta/logs/catalina.out
gzip /opt/local/jakarta/logs/catalina.out.$now
rm -rf /opt/local/jakarta/work/Apache/*
find /opt/local/jakarta/ -name core |xargs rm
# wait for tomcat cache to clear
sleep 30
# restart this pig
/opt/local/jakarta/bin/startup.sh
exit
So far, my problems are in this segment: Code:
if [ $tcpid != "" ]
do
(sudo kill $signal) $tcpid
sleep 5
else [ $tcpid = "" ]
echo "Java Stopped"
done
I want to see if the pid still exists (thus is defunct, needing sudo to kill), then kill -9 it every 5 seconds or so until it goes away. Once it's gone, it can move on to the rest of the script. What this one's doing is looping infinitely _and_ I keep getting errors about it trying to kill a process called '-9'. I've tried `sudo kill -9 $tcpid` or (sudo kill -9 $tcpid), but to no avail. Anyway, any pointers for how I can effectively pull this off? Thanks! Dave |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|