Script to delete a process if it exists


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script to delete a process if it exists
# 1  
Old 10-29-2010
Script to delete a process if it exists

I have an application that uses java but when the application stops, sometimes, for some odd reason, it leaves java threads behind. When the application next starts, it doesn't behave properly because of these previous java processes

What I want to do is create a script to check for these java threads/processes and if they exist, delete them....if they don't exist, do nothing

Please bare-in-mind that from a unix scripting point-of-view I'm a complete novice but here's what I've got so far:

Code:
if [ps -ef | grep -v 'grep' | grep java' -gt 0];
then
kill -9 `ps -ef | grep -v 'grep' | grep java |awk '{print $2}'`
fi

...what do you think, will this achieve what I want it to do?

Any advice / guidance would be gratefully received
Thanks
David

Last edited by Scott; 10-30-2010 at 05:42 AM.. Reason: Please use code tags
# 2  
Old 10-29-2010
(I'm not going to attempt a solution here because there is never a reason to routinely issue "kill -9" unless the correct signals have failed).

To keep the thread moving, some base questions.

Are you still using Solaris 10 ?
What Shell are you using?
Without automation does killing each process which mentions "java" clear the problem? Does the server crash eventually?
When there is not a problem, are there ever any "java" processes running?
# 3  
Old 11-19-2010
Script to delete a process if it exists

Hi Methyl

Sorry for the delay. After bouncing the server and starting the databases, everthing looked OK however the problem is now back.

In answer to your queries:
- I am using solaris 10
- I think its bourne shell that's being used

- There is a cronjob that should shutdown the java threads every night as part of the database shutdown & backup routine

The server hasn't crashed - why would it ?

The java threads are required as part of the application so they should always be present.

If I wasn't to use kill -9, is there a softer kill command I should be using to shutdown any rogue java threads ?

Any advise would be gratefully received
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Need help to delete special characters exists only at the end of the each record in UNIX file?

Hi, I have a file in unix with 15 columns.It consists special characters(#,$,^M,@,*,% etc)at the end of the each record.I want to remove these special characters.I used the following: Sed -e 's/ /g;s/ */ /g' . But It is removing special characters exists everywhere in the file(begining,middle... (24 Replies)
Discussion started by: rakeshp
24 Replies

2. Shell Programming and Scripting

Script needed to delete to the list of files in a directory based on last created & delete them

Hi My directory structure is as below. dir1, dir2, dir3 I have the list of files to be deleted in the below path as below. /staging/retain_for_2years/Cleanup/log $ ls -lrt total 0 drwxr-xr-x 2 nobody nobody 256 Mar 01 16:15 01-MAR-2015_SPDBS2 drwxr-xr-x 2 root ... (2 Replies)
Discussion started by: prasadn
2 Replies

3. Shell Programming and Scripting

script to tell whether there exists directory or not

Hi, I am writing a script as follows: #!/bin/sh set -x for i in `cat a`; do #sleep 3 print $i >> server.txt sleep 5 if test -d `vtask $i "' ls -lrt /opt/log/ '" ` ; then print $i >> 12.5.txt else print $i >> 12.0.txt fi done (7 Replies)
Discussion started by: dbashyam
7 Replies

4. Shell Programming and Scripting

Script to check file exists

Hi, I am trying to write a script which checks if any file exists with "*.log" or "*.out" in Directory below is the code #------------------ path=/abd/xyz/ if ; then echo "Good" else echo "Failure" fi #-------------------------- its always going to else part and printing... (8 Replies)
Discussion started by: ch33ry
8 Replies

5. Shell Programming and Scripting

Run script if new file exists.

Is there any way to have a script run (either on a web page or a shell script) when new files are put in a folder. E.g we have order response notification XML files uploaded to our server. They are uploaded via sftp. What i wondered if there was some way to monitor the contents and if new files... (4 Replies)
Discussion started by: timgolding
4 Replies

6. Shell Programming and Scripting

Script to check if file exists

guys, I am trying to write a script that does the following: it looks for a file in a specific directory and if the file is not there (NOT), it emails me. I have tried the following but its not working. It simply hangs up. Please help. if then mail -s 'blah blah blah' my email... (4 Replies)
Discussion started by: basisvasis
4 Replies

7. Shell Programming and Scripting

bash script quesiton - if any file exists then ...

I'd like a bash script to simply check to see if any file/files are present in a source directory, and if so move it/them to a target directory. I have this but it doesn't work: #!/bin/bash if then mv /source/* /target fi What is the right syntax? Thanks! (4 Replies)
Discussion started by: graysky
4 Replies

8. Shell Programming and Scripting

verify if a process exists (ps)

hi I want to verify that a process exists. if the process exists, then it means the service is up. ps -ef | grep monito returns an entry if the service is up. how to translate that in a shell script?? many thanks (4 Replies)
Discussion started by: melanie_pfefer
4 Replies

9. Shell Programming and Scripting

process already exists

I'm attempting to modify a script that ftps files from one machine to another (see this post ). I've been testing it a few times, and once I had to kill the test because it was taking forever, and I know it wasn't working. Now, when I try to test the script again, I'm getting the following: $... (4 Replies)
Discussion started by: kadishmj
4 Replies

10. Shell Programming and Scripting

Please help me with this script meant for checking /etc/passwd if a name exists

I'm trying to create a program that includes variety of duties. One of the duties includes deleting a user if the user name exist in the /etc/passwd file. how do i make that happen. those of you that know about this shell programming, please tell me what i should do after the shell reads... (4 Replies)
Discussion started by: TRUEST
4 Replies
Login or Register to Ask a Question