- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: running 'top' command in batch mode
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-05-2010 02:55 PM
тАО03-05-2010 02:55 PM
-----------
I am trying to run the top command in batch mode and would like to sort that on either the RES field or VIRT field, how do I do that?
What is the switch to sort any field in batch mode?
# top -b -n 1
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-05-2010 03:45 PM
тАО03-05-2010 03:45 PM
Re: running 'top' command in batch mode
HP-UX is different. There is no -b.
>would like to sort that on either the RES field or VIRT field, how do I do that?
You'll have to strip off the header and use sort -k.
Perhaps it would be using to use ps(1) and sort on its fields?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-05-2010 03:49 PM
тАО03-05-2010 03:49 PM
SolutionEven looking at the GNU/Linux 'top' command manpages indicates to me that you need to roll-your-own if you are running in batch mode. You might do something along these lines:
# top -b -n 1|awk '{if ($1~/[0-9]+/) {if ($5~/m/) {$5=int($5*1024*1024)};print}}'|sort -k5rn,5
This stripes the header liness (since they don't have a numeric first field. If the VIRT field units are "m"egabytes, then this field is scaled to match the other values in this column. You might need additional code for other scaling. The output is then piped to 'sort' and shown in descending size order.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-05-2010 04:02 PM
тАО03-05-2010 04:02 PM
Re: running 'top' command in batch mode
Thats exactly what I need.
Thanks for the responses guys.
Thanks,
Shabu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-18-2010 03:22 AM
тАО04-18-2010 03:22 AM
Re: running 'top' command in batch mode
It has a --top switch which will play back process data in a format similar to 'top' which by default will show the top 10 consumers of CPU for each sample period which is a minute. You can even tell it to sort of things like memory, I/O, etc and can change the number of processes reported and/or the sample period at collection time.
-mark