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 acer asus bios bsod computer crash drive driver drivers error ethernet excel freeze games gaming hard drive hardware hdmi internet laptop malware memory monitor motherboard music network obp operating system printer problem ram random registry router slow software sound trojan usb video virus vista wifi windows windows 7 windows 7 32 bit windows 7 64 bit windows xp wireless
Search
Search for:
Tech Support Guy Forums > Operating Systems > Linux and Unix >
shell script [plz help]

Reply  
Thread Tools
mccrack's Avatar
Junior Member with 2 posts.
 
Join Date: Dec 2004
Experience: Beginner
21-Dec-2004, 12:59 PM #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
Trusted Advisor with 18,705 posts.
 
Join Date: Apr 2003
Location: 1265 Lombardi Ave
Experience: Bocks of Rox
21-Dec-2004, 01: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 at 01:43 PM..
Squashman's Avatar
Trusted Advisor with 18,705 posts.
 
Join Date: Apr 2003
Location: 1265 Lombardi Ave
Experience: Bocks of Rox
21-Dec-2004, 01: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, 01: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
Trusted Advisor with 18,705 posts.
 
Join Date: Apr 2003
Location: 1265 Lombardi Ave
Experience: Bocks of Rox
21-Dec-2004, 02: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.
Whiteskin's Avatar
Senior Member with 2,051 posts.
 
Join Date: Nov 2002
Location: Alberta, Canada
Experience: Windows: Decent. Unix/Linux: Advanced +1
21-Dec-2004, 03:02 PM #6
I suppose that's something I ought to get onto; Learning awk and sed.
Squashman's Avatar
Trusted Advisor with 18,705 posts.
 
Join Date: Apr 2003
Location: 1265 Lombardi Ave
Experience: Bocks of Rox
21-Dec-2004, 04: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, 04: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.
Reply

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.

Search Tech Support Guy

Find the solution to your
computer problem!




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



Facebook Facebook Twitter Twitter TechGuy.tv TechGuy.tv Mobile TSG Mobile
You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 05:26 AM.
Copyright © 1996 - 2011 TechGuy, Inc. All rights reserved.

Powered by Cermak Technologies, Inc.