LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 07-26-2012, 10:21 AM   #1
j0sh10
LQ Newbie
 
Registered: Jun 2012
Posts: 2

Rep: Reputation: Disabled
Talking Bash Script, Kill proccess by pulling from PID file


This is what I have right now in the bash script:

ps aux | grep glassfish | grep domain1 | gawk '{print $2}' | xargs kill -9

The problem with this is that if someone else is logged in and pulling something related to glassfish, it wil pull that PID as well. Thus resulting in killing the wrong PID.

So My question is how do I fix what I have to only pull the correct PID, and how do I rewrite it to pull the PID from the PID file that glassfish generates.

Thank you for your time.
Josh
 
Old 07-26-2012, 10:41 AM   #2
dmdeb
Member
 
Registered: Jul 2007
Location: Germany
Distribution: Debian
Posts: 45

Rep: Reputation: 6
Quote:
Originally Posted by j0sh10 View Post
This is what I have right now in the bash script:

ps aux | grep glassfish | grep domain1 | gawk '{print $2}' | xargs kill -9

The problem with this is that if someone else is logged in and pulling something related to glassfish, it wil pull that PID as well. Thus resulting in killing the wrong PID.

So My question is how do I fix what I have to only pull the correct PID, and how do I rewrite it to pull the PID from the PID file that glassfish generates.

Thank you for your time.
Josh
Just a silly question: If you don't want to see glassfish processes belonging to other users, then why do you use "ps aux" instead of just "ps ux"?
 
Old 07-26-2012, 10:46 AM   #3
j0sh10
LQ Newbie
 
Registered: Jun 2012
Posts: 2

Original Poster
Rep: Reputation: Disabled
Not a silly question.....

this was pasted from old code.......
The ps a (removing the "only yourself") has since been removed.
 
Old 07-26-2012, 11:13 AM   #4
dmdeb
Member
 
Registered: Jul 2007
Location: Germany
Distribution: Debian
Posts: 45

Rep: Reputation: 6
Quote:
Originally Posted by j0sh10 View Post
Not a silly question.....

this was pasted from old code.......
The ps a (removing the "only yourself") has since been removed.
Oh wow... and it still fetches the wrong PID at times? That's quite a surprise!
 
Old 07-26-2012, 11:44 AM   #5
PTrenholme
Senior Member
 
Registered: Dec 2004
Location: Olympia, WA, USA
Distribution: Fedora, (K)Ubuntu
Posts: 4,187

Rep: Reputation: 354Reputation: 354Reputation: 354Reputation: 354
If your distribution supports it, you might find the killall command solves your problem somewhat more easily.

<edit>
Here's a bit of the man killall output
Code:
KILLALL(1)                                       User Commands                                       KILLALL(1)

NAME
       killall - kill processes by name

SYNOPSIS
       killall [-Z,--context pattern] [-e,--exact] [-g,--process-group] [-i,--interactive] [-o,--older-than
       TIME] [-q,--quiet] [-r,--regexp] [-s,--signal signal] [-u,--user user] [-v,--verbose] [-w,--wait]
       [-y,--younger-than TIME] [-I,--ignore-case] [-V,--version] [--] name ...
       killall -l
       killall -V,--version

DESCRIPTION
       killall  sends  a  signal  to  all processes running any of the specified commands. If no signal name is
       specified, SIGTERM is sent.

       Signals can be specified either by name (e.g. -HUP or -SIGHUP ) or by number (e.g. -1) or by option -s.

       If the command name is not regular expression (option -r) and contains a slash (/), processes  executing
       that particular file will be selected for killing, independent of their name.

       killall  returns  a zero return code if at least one process has been killed for each listed command, or
       no commands were listed and at least one process matched the -u and -Z search criteria. killall  returns
       non-zero otherwise.

       A killall process never kills itself (but may kill other killall processes).
</edit>

Last edited by PTrenholme; 07-26-2012 at 10:49 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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



Similar Threads
Thread Thread Starter Forum Replies Last Post
kill < file (Feeding kill from file), PID, <, awk, grep jaffd Programming 4 04-09-2010 04:06 PM
Setting up cron to proccess a Bash Script to run every 15 minutes jamtech Programming 3 07-30-2007 03:32 PM
PID Kill Script or command ? Webmin rapture_1 Linux - General 1 11-02-2005 11:11 AM
small bash script to kill a PID flosch Linux - General 3 05-06-2004 09:28 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 03:45 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration