Re: OT - shell script to kill a process

2007-07-10 Thread Chris Sheffield

Excellent. Thanks, Chris.

On Jul 9, 2007, at 4:06 PM, chris bohnert wrote:


killall ProcessName should do what you want

--
cb

On 7/9/07, Chris Sheffield [EMAIL PROTECTED] wrote:


My Unix scripting knowledge leaves a bit to be desired, so I thought
I'd ask here for some help.

I have a Vise installer for OS X that needs to check for and kill our
own process if it's running. The installer will be authenticated when
running. I need a shell script that I can execute from within the
installer that will determine, by name, if a given process is
running, and then kill it dead if so. Can someone help?

Thanks,
Chris


--
Chris Sheffield
Read Naturally
The Fluency Company
http://www.readnaturally.com
--


___
use-revolution mailing list
use-revolution@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your
subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution



___
use-revolution mailing list
use-revolution@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your  
subscription preferences:

http://lists.runrev.com/mailman/listinfo/use-revolution


--
Chris Sheffield
Read Naturally
The Fluency Company
http://www.readnaturally.com
--


___
use-revolution mailing list
use-revolution@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution


Re: OT - shell script to kill a process

2007-07-10 Thread Chris Sheffield
Well, Ken. It turns out I think I need to go with your method. The  
'killall' command is definitely more concise, but it turns out that I  
am going to have to do a partial search on the path to the process  
exe just to make sure I get the right one, and killall doesn't seem  
to allow that.


I've got another question for you though. It concerns the 'cut -d\  - 
f2' part of this. This doesn't seem to be working correctly. Can you  
explain more what's supposed to happen here? It seems to just be  
returning an empty string, so a valid pid is never passed on. I've  
tried it using TextEdit as well as using my own process in the  
command. Any thoughts?


Thanks,
Chris


On Jul 9, 2007, at 4:03 PM, Ken Ray wrote:


On Mon, 9 Jul 2007 14:46:32 -0600, Chris Sheffield wrote:


My Unix scripting knowledge leaves a bit to be desired, so I thought
I'd ask here for some help.

I have a Vise installer for OS X that needs to check for and kill our
own process if it's running. The installer will be authenticated when
running. I need a shell script that I can execute from within the
installer that will determine, by name, if a given process is
running, and then kill it dead if so. Can someone help?


Well, it's ugly, but you can execute this:

ps -awx | grep 'TextEdit' | grep -v 'grep' | cut -d\  -f2 | xargs -I
pid kill -9 pid

A few notes:
  - I'm using TextEdit as the app I want to close - replace your app
name here (to see what I'm parsing, execute 'ps -awx' in the Terminal
by itself).
  - This is all one line, no returns here
  - There are actually two spaces after the d\ and before the -f2.

Here's what it means (for those wondering):

  (ps -awx) = Get a list of all currently running processes with full
path names.

  ( | grep 'TextEdit') = Pipe the result to 'grep' (the regex engine)
and return any lines that contain 'TextEdit'. This will return TWO
lines, one with the path to TextEdit on it, and the other one is the
actual 'grep' call that is trying to find 'TextEdit'.

  ( | grep -v 'grep') = Pipe the result to 'grep' again, but this time
ignore any lines that have 'grep' in it. (Sneaky!)

  ( cut -d\  -f2) = Extract (cut) the second space-delimited word
in the resulting string (-d means use a delimiter, \  is the
delimiter to use (has to be escaped because spaces normally signify a
change of parameters, etc. on the command line), -f2 means look for
the second space-delimited field in the string)

  ( | xargs -I pid kill -9 pid) = Pipe the result (the process ID)  
into

a variable called 'pid' that will replace the argument variable 'pid'
in the call to the 'kill' command (normally to kill a process it would
look like kill -9 1012)).

HTH,

Ken Ray
Sons of Thunder Software, Inc.
Email: [EMAIL PROTECTED]
Web Site: http://www.sonsothunder.com/
___
use-revolution mailing list
use-revolution@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your  
subscription preferences:

http://lists.runrev.com/mailman/listinfo/use-revolution


--
Chris Sheffield
Read Naturally
The Fluency Company
http://www.readnaturally.com
--


___
use-revolution mailing list
use-revolution@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution


Re: OT - shell script to kill a process

2007-07-10 Thread Chris Sheffield

Okay, I think I figured out the problem.

The pid as returned from ps has a different number of leading spaces  
depending on the number of digits in the pid. So using a set value  
for the -f option doesn't seem to work. For example, if the pid has  
four digits, using 2 works since the pid has 2 leading spaces. But if  
it has 3 digits, you have to use 3 to get the pid returned correctly  
since it has 3 leading spaces. Am I making sense? It's kind of  
confusing to me. Anyway, can you think of a way around this? Is there  
some other command that would work instead of cut, or some other form  
of cut maybe?


Thanks again.


On Jul 10, 2007, at 9:28 AM, Chris Sheffield wrote:



I've got another question for you though. It concerns the 'cut -d\   
-f2' part of this. This doesn't seem to be working correctly. Can  
you explain more what's supposed to happen here? It seems to just  
be returning an empty string, so a valid pid is never passed on.  
I've tried it using TextEdit as well as using my own process in the  
command. Any thoughts?


--
Chris Sheffield
Read Naturally
The Fluency Company
http://www.readnaturally.com
--


___
use-revolution mailing list
use-revolution@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution


Re: OT - shell script to kill a process

2007-07-10 Thread chris bohnert

Chris,

Try this:

 ps -awx | awk '{print $2}'

if that prints you a list of pid's you should be good to replace the cut
pipe with the awk command.  By the way, what version of os X are you
running..mine doesn't seem to behave as you describe.

--
cb

On 7/10/07, Chris Sheffield [EMAIL PROTECTED] wrote:


Okay, I think I figured out the problem.

The pid as returned from ps has a different number of leading spaces
depending on the number of digits in the pid. So using a set value
for the -f option doesn't seem to work. For example, if the pid has
four digits, using 2 works since the pid has 2 leading spaces. But if
it has 3 digits, you have to use 3 to get the pid returned correctly
since it has 3 leading spaces. Am I making sense? It's kind of
confusing to me. Anyway, can you think of a way around this? Is there
some other command that would work instead of cut, or some other form
of cut maybe?

Thanks again.


On Jul 10, 2007, at 9:28 AM, Chris Sheffield wrote:


 I've got another question for you though. It concerns the 'cut -d\
 -f2' part of this. This doesn't seem to be working correctly. Can
 you explain more what's supposed to happen here? It seems to just
 be returning an empty string, so a valid pid is never passed on.
 I've tried it using TextEdit as well as using my own process in the
 command. Any thoughts?

--
Chris Sheffield
Read Naturally
The Fluency Company
http://www.readnaturally.com
--


___
use-revolution mailing list
use-revolution@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your
subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution



___
use-revolution mailing list
use-revolution@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution


Re: OT - shell script to kill a process

2007-07-10 Thread Ken Ray
On Tue, 10 Jul 2007 09:28:01 -0600, Chris Sheffield wrote:

 I've got another question for you though. It concerns the 'cut -d\  
 -f2' part of this. This doesn't seem to be working correctly. Can you 
 explain more what's supposed to happen here? 

Yes, the cut basically extracts a delimited chunk of data from the 
string. So run this part of the command in the Terminal with TextEdit 
running:

  ps -awx | grep 'TextEdit' | grep -v 'grep'

I get this:

 5460  ??  S  0:00.25 
/Applications/TextEdit.app/Contents/MacOS/TextEdit -psn_0_21626881

With a preceding space in front of the 5460. So as I put in my previous 
email:

   ( cut -d\  -f2) = Extract (cut) the second space-delimited word
 in the resulting string (-d means use a delimiter, \  is the
 delimiter to use (has to be escaped because spaces normally signify a
 change of parameters, etc. on the command line), -f2 means look for
 the second space-delimited field in the string)

This means it should look for the second space-delimited chunk. So then 
run it up to the end of the 'cut':

  ps -awx | grep 'TextEdit' | grep -v 'grep' | cut -d\  -f2

I get 5460. This is then piped to the kill command to kill. Is it 
possible you either (a) don't have two spaces between the \ and the 
-f2 (if so you'll get a bad delimiter error message in the 
Terminal), or (b) perhaps your process line isn't the same as mine?

Ken Ray
Sons of Thunder Software, Inc.
Email: [EMAIL PROTECTED]
Web Site: http://www.sonsothunder.com/
___
use-revolution mailing list
use-revolution@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution


Re: OT - shell script to kill a process

2007-07-10 Thread Ken Ray
On Tue, 10 Jul 2007 10:55:14 -0600, chris bohnert wrote:

 Chris,
 
 Try this:
 
  ps -awx | awk '{print $2}'
 
 if that prints you a list of pid's you should be good to replace the cut
 pipe with the awk command.  By the way, what version of os X are you
 running..mine doesn't seem to behave as you describe.

Ah... actually use {print $1} (you want the first chunk)... so try this:

ps -awx | grep 'TextEdit' | grep -v 'grep' | awk '{print $1}' | xargs 
-I pid kill -9 pid

(all one line of course...)

Ken Ray
Sons of Thunder Software, Inc.
Email: [EMAIL PROTECTED]
Web Site: http://www.sonsothunder.com/
___
use-revolution mailing list
use-revolution@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution


Re: OT - shell script to kill a process

2007-07-10 Thread Chris Sheffield
Excellent. That seems to work just fine. Although I had to change the  
2 to 1, since the pid is the first column returned.


I'm running 10.4.10. What's different on yours?


On Jul 10, 2007, at 10:55 AM, chris bohnert wrote:


Chris,

Try this:

 ps -awx | awk '{print $2}'

if that prints you a list of pid's you should be good to replace  
the cut

pipe with the awk command.  By the way, what version of os X are you
running..mine doesn't seem to behave as you describe.

--
cb

On 7/10/07, Chris Sheffield [EMAIL PROTECTED] wrote:


Okay, I think I figured out the problem.

The pid as returned from ps has a different number of leading spaces
depending on the number of digits in the pid. So using a set value
for the -f option doesn't seem to work. For example, if the pid has
four digits, using 2 works since the pid has 2 leading spaces. But if
it has 3 digits, you have to use 3 to get the pid returned correctly
since it has 3 leading spaces. Am I making sense? It's kind of
confusing to me. Anyway, can you think of a way around this? Is there
some other command that would work instead of cut, or some other form
of cut maybe?

Thanks again.


On Jul 10, 2007, at 9:28 AM, Chris Sheffield wrote:


 I've got another question for you though. It concerns the 'cut -d\
 -f2' part of this. This doesn't seem to be working correctly. Can
 you explain more what's supposed to happen here? It seems to just
 be returning an empty string, so a valid pid is never passed on.
 I've tried it using TextEdit as well as using my own process in the
 command. Any thoughts?

--
Chris Sheffield
Read Naturally
The Fluency Company
http://www.readnaturally.com
--


___
use-revolution mailing list
use-revolution@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your
subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution



___
use-revolution mailing list
use-revolution@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your  
subscription preferences:

http://lists.runrev.com/mailman/listinfo/use-revolution


___
use-revolution mailing list
use-revolution@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution


Re: OT - shell script to kill a process

2007-07-10 Thread Chris Sheffield
Tried this. All parts seem to work except now I'm getting an  
operation not permitted error from the kill command. I'm running it  
with sudo, so I don't understand why this would happen. But I did  
verify that the correct pid is now getting returned. In fact, the  
entire error message reads, kill: 1031: Operation not permitted,  
and 1031 is the correct pid.


Any other thoughts? :-(



On Jul 10, 2007, at 11:01 AM, Ken Ray wrote:

Ah... actually use {print $1} (you want the first chunk)... so try  
this:


ps -awx | grep 'TextEdit' | grep -v 'grep' | awk '{print $1}' | xargs
-I pid kill -9 pid


--
Chris Sheffield
Read Naturally
The Fluency Company
http://www.readnaturally.com
--


___
use-revolution mailing list
use-revolution@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution


OT - shell script to kill a process

2007-07-09 Thread Chris Sheffield
My Unix scripting knowledge leaves a bit to be desired, so I thought  
I'd ask here for some help.


I have a Vise installer for OS X that needs to check for and kill our  
own process if it's running. The installer will be authenticated when  
running. I need a shell script that I can execute from within the  
installer that will determine, by name, if a given process is  
running, and then kill it dead if so. Can someone help?


Thanks,
Chris


--
Chris Sheffield
Read Naturally
The Fluency Company
http://www.readnaturally.com
--


___
use-revolution mailing list
use-revolution@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution


Re: OT - shell script to kill a process

2007-07-09 Thread Ken Ray
On Mon, 9 Jul 2007 14:46:32 -0600, Chris Sheffield wrote:

 My Unix scripting knowledge leaves a bit to be desired, so I thought 
 I'd ask here for some help.
 
 I have a Vise installer for OS X that needs to check for and kill our 
 own process if it's running. The installer will be authenticated when 
 running. I need a shell script that I can execute from within the 
 installer that will determine, by name, if a given process is 
 running, and then kill it dead if so. Can someone help?

Well, it's ugly, but you can execute this:

ps -awx | grep 'TextEdit' | grep -v 'grep' | cut -d\  -f2 | xargs -I 
pid kill -9 pid

A few notes:
  - I'm using TextEdit as the app I want to close - replace your app 
name here (to see what I'm parsing, execute 'ps -awx' in the Terminal 
by itself).
  - This is all one line, no returns here
  - There are actually two spaces after the d\ and before the -f2.

Here's what it means (for those wondering):

  (ps -awx) = Get a list of all currently running processes with full 
path names.

  ( | grep 'TextEdit') = Pipe the result to 'grep' (the regex engine) 
and return any lines that contain 'TextEdit'. This will return TWO 
lines, one with the path to TextEdit on it, and the other one is the 
actual 'grep' call that is trying to find 'TextEdit'.

  ( | grep -v 'grep') = Pipe the result to 'grep' again, but this time 
ignore any lines that have 'grep' in it. (Sneaky!)

  ( cut -d\  -f2) = Extract (cut) the second space-delimited word 
in the resulting string (-d means use a delimiter, \  is the 
delimiter to use (has to be escaped because spaces normally signify a 
change of parameters, etc. on the command line), -f2 means look for 
the second space-delimited field in the string)

  ( | xargs -I pid kill -9 pid) = Pipe the result (the process ID) into 
a variable called 'pid' that will replace the argument variable 'pid' 
in the call to the 'kill' command (normally to kill a process it would 
look like kill -9 1012)).

HTH,

Ken Ray
Sons of Thunder Software, Inc.
Email: [EMAIL PROTECTED]
Web Site: http://www.sonsothunder.com/
___
use-revolution mailing list
use-revolution@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution


Re: OT - shell script to kill a process

2007-07-09 Thread chris bohnert

killall ProcessName should do what you want

--
cb

On 7/9/07, Chris Sheffield [EMAIL PROTECTED] wrote:


My Unix scripting knowledge leaves a bit to be desired, so I thought
I'd ask here for some help.

I have a Vise installer for OS X that needs to check for and kill our
own process if it's running. The installer will be authenticated when
running. I need a shell script that I can execute from within the
installer that will determine, by name, if a given process is
running, and then kill it dead if so. Can someone help?

Thanks,
Chris


--
Chris Sheffield
Read Naturally
The Fluency Company
http://www.readnaturally.com
--


___
use-revolution mailing list
use-revolution@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your
subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution



___
use-revolution mailing list
use-revolution@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution


Re: OT - shell script to kill a process

2007-07-09 Thread Ken Ray
On Mon, 9 Jul 2007 17:06:23 -0500, chris bohnert wrote:

 killall ProcessName should do what you want

Oh, man! I could have been doing it the EASY way...

:-D

Ken Ray
Sons of Thunder Software, Inc.
Email: [EMAIL PROTECTED]
Web Site: http://www.sonsothunder.com/
___
use-revolution mailing list
use-revolution@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution