The UNIX and Linux Forums  
Hello and Welcome from to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
.
google unix.com



UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
what is kill -6 command in unix abhi_123 UNIX for Dummies Questions & Answers 2 06-20-2008 03:38 AM
Kill Command sonali UNIX for Dummies Questions & Answers 4 01-03-2007 03:30 AM
the kill command kelogs1347 High Level Programming 2 11-23-2006 04:23 AM
Is there anu command or way to kill zombis? umen UNIX for Dummies Questions & Answers 4 05-21-2006 05:48 AM
kill command Rush UNIX for Dummies Questions & Answers 1 03-27-2003 04:54 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 08-04-2008
johnl johnl is offline
Registered User
  
 

Join Date: May 2008
Posts: 15
How to kill top command using script?

Hi all,

I am using top command in my script to redirect output to temp file. I used kill -9 `ps -ef|grep top|grep -v grep|awk '{print $2}'` to kill top command in my script, but it is not working? Can you please tell how to kill top command in my script?
  #2 (permalink)  
Old 08-04-2008
sysgate's Avatar
sysgate sysgate is offline Forum Advisor  
Unix based
  
 

Join Date: Nov 2006
Location: Bulgaria
Posts: 1,322
Why do you have to kill the top command in such manner, how are you using that command, can we see the relevant snippet of this script ? Else, you can always use "pkill -9 top" but be careful, this will kill any process with " * top * " pattern in the name, it's pretty harsh, so watch out.
  #3 (permalink)  
Old 08-04-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
If you are running it in the background, just store $! in a variable just after starting it, and kill $! when you need to.

top has options to tell how many iterations to run; perhaps you should be using those instead.

Don't use kill -9 unless you know what you are doing.
  #4 (permalink)  
Old 08-04-2008
shamrock shamrock is offline Forum Advisor  
Registered User
  
 

Join Date: Oct 2007
Location: USA
Posts: 750
Quote:
Originally Posted by johnl View Post
Hi all,

I am using top command in my script to redirect output to temp file. I used kill -9 `ps -ef|grep top|grep -v grep|awk '{print $2}'` to kill top command in my script, but it is not working? Can you please tell how to kill top command in my script?
Use the -f option to top...it outputs one display to the named file and exits automatically.

Code:
top -f /path/to/outfile
  #5 (permalink)  
Old 08-04-2008
broli's Avatar
broli broli is offline
Registered User
  
 

Join Date: Dec 2007
Location: Argentina
Posts: 215
Quote:
Originally Posted by shamrock View Post
Use the -f option to top...it outputs one display to the named file and exits automatically.

Code:
top -f /path/to/outfile
depends on what version of top
in my end, the option is
-b (for batch)
and -n 1 (for 1 iteration)
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 10:35 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0