LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices



Reply
 
Search this Thread
Old 10-06-2005, 11:07 AM   #1
fatrandy13
Member
 
Registered: Jun 2004
Location: new jersey
Distribution: anything debian based, long live apt-get
Posts: 230

Rep: Reputation: 30
Automating the "killing" process via a shell script


when I log into the UNIX server at work, it loads up twm by defualt, and the very first thing i do every morning is kill twm and run startkde. I want to automate this....

I started a shell script, but seem to be stuck..


ps -U myname | grep twm | nawk '{ print $1}'

store that pid number in a variable, then kill it....

i would appreciate any help....if i was unclear at all, let me know.

Last edited by fatrandy13; 10-06-2005 at 11:28 AM.
 
Old 10-06-2005, 11:37 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374
Hi,

VAR="`ps -U myname | grep twm | nawk '{ print $1}'`"
kill $VAR


Or, all in one go:

kill `ps -U myname | grep twm | nawk '{ print $1}'`

The backticks (upper left corner on most keyboards) around the command executes it and any output is given to kill (or a variable).

Hope this helps.
 
Old 10-06-2005, 11:42 AM   #3
fatrandy13
Member
 
Registered: Jun 2004
Location: new jersey
Distribution: anything debian based, long live apt-get
Posts: 230

Original Poster
Rep: Reputation: 30
Thanks a lot. After messing around with your suggestion, and trying a few other things I came up with this:

ps -U myname | grep twm | cut -c1-6 | xargs kill > /dev/null

I appreciate the help.
 
Old 09-13-2007, 08:59 PM   #4
montypython0102
LQ Newbie
 
Registered: Sep 2007
Posts: 1

Rep: Reputation: 0
parens surround pid?

I tried this:

kill `ps -ef | grep processname | awk '{print $2}'`

The error that I keep getting is:

kill (12345): process does not exist.

This tells me that for some reason the pid gets enclosed in parens!

Any help?
 
Old 09-14-2007, 12:46 AM   #5
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374
Hi,

It is probably (also) trying to kill the grep process itself.

ps -ef | grep something will not only show the something process (if still active), but also the grep something part.

Try changing it to: kill `ps -ef | grep [Pp]rocessname | awk '{print $2}'`

Hope this helps.

BTW: Try starting a new thread next time. Although the problem seems simular, this could be seen as thread hijacking.
 
Old 09-14-2007, 12:59 AM   #6
dive
Senior Member
 
Registered: Aug 2003
Location: UK
Distribution: Slackware
Posts: 3,211

Rep: Reputation: 293Reputation: 293Reputation: 293
You could also use 'pgrep' on the process name. This will not return the pid of grep.

kill `pgrep twm`
 
  


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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
bash script: using "select" to show multi-word options? (like "option 1"/"o zidane_tribal Programming 6 03-21-2013 11:35 AM
Shell Script: Find "Word" Run "Command" granatica Linux - Software 5 07-25-2007 08:42 AM
Starting Java from shell script (Exception in thread "main") rolf_mueller Linux - Software 5 10-30-2004 03:11 AM
1. shell script "find and replace" on text 2. java GUI application randomx Programming 4 03-05-2004 02:01 PM
Writing shell script called "convert" bluewolf Programming 3 02-04-2003 11:52 PM


All times are GMT -5. The time now is 09:57 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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration