LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
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, 10: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 10:28 AM.
 
Old 10-06-2005, 10:37 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
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, 10: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, 07: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-13-2007, 11:46 PM   #5
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
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-13-2007, 11:59 PM   #6
dive
Senior Member
 
Registered: Aug 2003
Location: UK
Distribution: Slackware
Posts: 3,467

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

kill `pgrep twm`
 
  


Reply



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 7 12-19-2015 01:03 AM
Shell Script: Find "Word" Run "Command" granatica Linux - Software 5 07-25-2007 07:42 AM
Starting Java from shell script (Exception in thread "main") rolf_mueller Linux - Software 5 10-30-2004 02:11 AM
1. shell script "find and replace" on text 2. java GUI application randomx Programming 4 03-05-2004 01:01 PM
Writing shell script called "convert" bluewolf Programming 3 02-04-2003 10:52 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 09:48 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