The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



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

 
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1 (permalink)  
Old 04-13-2006
dkaplowitz dkaplowitz is offline
Registered User
  
 

Join Date: Jun 2004
Location: ~Philadelphia
Posts: 63
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
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 09:44 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0