Unix/Linux Go Back    


Shell Programming and Scripting Unix shell scripting - KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and shell scripts and shell scripting languages here.

Top utility in bash for loop

Shell Programming and Scripting


Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 12-02-2012
mail2vivek1 mail2vivek1 is offline
Registered User
 
Join Date: Apr 2012
Last Activity: 2 December 2012, 8:07 PM EST
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
Top utility in bash for loop

Dear All,

is it possible to use top utility in for loop?

I am trying to get top swap space consuming processes in my for loop.
I got multiple way (using /proc FS) however have anybody used top command in for loop? Using /proc FS giving solutionbut itrs more complex. Please suggest if anybody has simpler solution
Sponsored Links
    #2  
Old Unix and Linux 12-02-2012
Yoda's Unix or Linux Image
Yoda Yoda is offline Forum Advisor  
Jedi Master
 
Join Date: Jan 2012
Last Activity: 27 July 2016, 4:37 PM EDT
Location: Galactic Empire
Posts: 3,500
Thanks: 247
Thanked 1,262 Times in 1,185 Posts
You can do the following to achieve this:-
  • Run top command
top
  • Press O and then p to select sort by SWAP usage.
  • Press W to save this settings it to .toprc file
  • Now you can put below command in loop to get the list of processes sorted by SWAP usage:-
top -n 1

I hope this helps.
The Following User Says Thank You to Yoda For This Useful Post:
mail2vivek1 (12-02-2012)
Sponsored Links
    #3  
Old Unix and Linux 12-02-2012
mail2vivek1 mail2vivek1 is offline
Registered User
 
Join Date: Apr 2012
Last Activity: 2 December 2012, 8:07 PM EST
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
Thanks for reply Bipin!!!

However this method works only on terminal... any trick to use it in bash script/loop...

I meant, how the script will understand option O and P in for loop/shell script
    #4  
Old Unix and Linux 12-02-2012
Yoda's Unix or Linux Image
Yoda Yoda is offline Forum Advisor  
Jedi Master
 
Join Date: Jan 2012
Last Activity: 27 July 2016, 4:37 PM EDT
Location: Galactic Empire
Posts: 3,500
Thanks: 247
Thanked 1,262 Times in 1,185 Posts
Once you have saved the settings to .toprc using W option, then you don't have to use option O & p anymore. Your top command will always display processes sorted by SWAP usage. Please give it a try and see if you are getting the desired result.
Sponsored Links
    #5  
Old Unix and Linux 12-03-2012
hombreopaco's Unix or Linux Image
hombreopaco hombreopaco is offline
Registered User
 
Join Date: Sep 2011
Last Activity: 26 August 2014, 12:56 PM EDT
Posts: 20
Thanks: 0
Thanked 4 Times in 4 Posts
Hi, you can use something like:

Code:
top -o size -n 1


Last edited by Franklin52; 12-03-2012 at 06:21 AM.. Reason: Please use code tags for data and code samples
Sponsored Links
Closed

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Using variables created sequentially in a loop while still inside of the loop [bash] DeCoTwc Shell Programming and Scripting 2 06-23-2009 04:59 PM
top command line utility antoniomorandi Programming 6 11-20-2007 07:38 PM
Unload utility with loop method cedrichiu Shell Programming and Scripting 1 07-02-2007 08:55 AM



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