Mourning the loss of our friend, WhitPhil.
There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
Search
 
Linux and Unix
Tag Cloud
access audio black screen blue screen boot bsod connection crash dell desktop driver drivers dvd email error excel firefox hard drive hardware hijackthis internet keyboard laptop malware monitor network networking outlook problem processor recovery registry cleaner router safe mode screen slow sound spyware trojan upgrade vba video virus vista vundo windows windows 7 windows vista windows xp wireless
Search
Search for:
Tech Support Guy Forums > Operating Systems > Linux and Unix >
shell script [plz help]

Tip: Click here to scan for System Errors and Optimize PC performance
[ Sponsored Link ]

Closed Thread
 
Thread Tools
mccrack's Avatar
Junior Member with 2 posts.
 
Join Date: Dec 2004
Experience: Beginner
21-Dec-2004, 11:59 AM #1
shell script [plz help]
Morning Ladies & Gents .

I need to cron a script that kills a process every evening . ( the cron's not the prob, it's the script ) . Getting the PID too kill is the problem . This is what i'm doing .

--------------------------------------------------------------
#/bin/bash
pid= ps -ef | grep process | grep -v grep | awk '{print $2}'
# the above gives me the PID
kill -9 $pid
--------------------------------------------------------------

the kill -9 however cant see the result of $pid

any ideas will be greatly appreciated.



Regards

Ronald
Squashman's Avatar
Distinguished Member with 14,988 posts.
 
Join Date: Apr 2003
Location: 1265 Lombardi Ave
Experience: IIAHYAYCESA,YAADA!
21-Dec-2004, 12:35 PM #2
Is there more than one PID associated with that process?
Do you have rights to kill the process?
What user is trying to kill the process?
What happens when you do it from the command line?
Can you just keep piping the output to the kill command?

Last edited by LwdSquashman : 21-Dec-2004 12:43 PM.
Squashman's Avatar
Distinguished Member with 14,988 posts.
 
Join Date: Apr 2003
Location: 1265 Lombardi Ave
Experience: IIAHYAYCESA,YAADA!
21-Dec-2004, 12:46 PM #3
Oh crap. I know what the problem is. You need that in Single back ticks.

pid=`ps -ef | grep process | grep -v grep | awk '{print $2}'`
mccrack's Avatar
Junior Member with 2 posts.
 
Join Date: Dec 2004
Experience: Beginner
21-Dec-2004, 12:53 PM #4
You are an absoloute star!!!!! Thanx , that did the trick !!!!
Hmmm, back ticks .... never would have thought.

regards

ronald
Squashman's Avatar
Distinguished Member with 14,988 posts.
 
Join Date: Apr 2003
Location: 1265 Lombardi Ave
Experience: IIAHYAYCESA,YAADA!
21-Dec-2004, 01:05 PM #5
Quote:
Originally Posted by mccrack
You are an absoloute star!!!!! Thanx , that did the trick !!!!
Hmmm, back ticks .... never would have thought.

regards

ronald
That is how you have to do it. Otherwise PID actually equals ps -ef | grep process | grep -v grep | awk '{print $2}'. Instead of the actual PID number.

Putting everything in back ticks tells your shell to execute everything within the back ticks.

I feel stupid for not seeing it right away.
__________________
I hate asking the same question twice!
How to ask questions the smart way!
Microsoft MVP - User Desktop Experience
Whiteskin's Avatar
Distinguished Member with 2,051 posts.
 
Join Date: Nov 2002
Location: Alberta, Canada
Experience: Windows: Decent. Unix/Linux: Advanced +1
21-Dec-2004, 02:02 PM #6
I suppose that's something I ought to get onto; Learning awk and sed.
Squashman's Avatar
Distinguished Member with 14,988 posts.
 
Join Date: Apr 2003
Location: 1265 Lombardi Ave
Experience: IIAHYAYCESA,YAADA!
21-Dec-2004, 03:21 PM #7
Quote:
Originally Posted by Whiteskin
I suppose that's something I ought to get onto; Learning awk and sed.
I have been starting to use them both the last couple of months. The more I use them the more I like them. There is so much I don't know about either of them. They are both very powerful programs.
tsunam's Avatar
Senior Member with 1,246 posts.
 
Join Date: Sep 2003
Experience: Linux~su
21-Dec-2004, 03:39 PM #8
I love awk, great useful app. I should learn sed but I'd have to learn the nromal imput method of it and ughuu~ it looks ugly.
Closed Thread Bookmark and Share

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.

Smart Search

Find your solution!



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who want to help you solve your computer problems. See our Welcome Guide to get started.

Thread Tools


You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -5. The time now is 07:55 AM.
Copyright © 1996 - 2009 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.
Powered by Cermak Technologies, Inc.