Solved

Capturing information from a top script

Posted on 2004-09-02
5
457 Views
Last Modified: 2013-12-26
I am writing a script in SH and want to added to my current script to obtain this output specific area from the top command

CPU TTY   PID    USERNAME PRI  NI   SIZE     RES   STATE    TIME  %WCPU  %CPU  COMMAND
 1       ?    22557  SQL          138 39   2016K   596K  sleep      0:33   79.73      70.45  compress


There was a script that that I found on here that output for uptime this way, what changes can I make to this script
to work with top.

Here was the script I found

uptime | sed -e 's/.*: //' -e 's/ //g' | awk -F , ' { print "A="$1 "\nB=" $2 "\nC=" $3 } '


I tried using top -n 1 and it prints out the other stuff from top that is not needed
0
Comment
Question by:eaglesprings
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 48

Expert Comment

by:Tintin
ID: 11969786
top -n 1|grep '%'

0
 
LVL 48

Expert Comment

by:Tintin
ID: 11969799
Whoops.  I was working with top -n 1 output on a Solaris box which has a different format.

top -n 1|sed -n 8p

You may need to adjust the line number on the sed statement depending on how many lines top -n 1 outputs on your system.
0
 

Author Comment

by:eaglesprings
ID: 11970055
I am working on HP UX
0
 
LVL 45

Assisted Solution

by:sunnycoder
sunnycoder earned 100 total points
ID: 11970481
err, isnt top interactive ... since all you are interested in is one time system snapshot, why not use ps with appropriate arguments

 ps -p 1 -o "cpu longtname pid uname pri ni sz rssize state time pcpu comm"

does nearly the same thing ... the exact options may be bit different for your unix but ps might be better to use here
0
 
LVL 38

Accepted Solution

by:
yuzh earned 400 total points
ID: 11970483
For HP-UX,

you can use something like:

top -n 1 -d 1 t | sed -n 6p

the output will looks like:

Memory: 55524K (5152K) real, 111180K (4020K) virtual, 316900K free  Page# 1/147


 TTY  PID USERNAME PRI NI   SIZE    RES STATE    TIME %WCPU  %CPU COMMAND
  ?  1442 root     154 20   608K   948K sleep   14:54  0.12  0.12 dtgreet

 
Note that: if you redirect the output to a file, it is in ONE line, looks like:

Memory: 54664K (7288K) real, 110540K (7104K) virtual, 317868K free  Page# 1/145ESC[10;2HTTY  PID USERN
AME PRI NI   SIZE    RES STATE    TIME %WCPU  %CPU COMMANDESC[11;3H?  1442 rootESC[5C154 20   608K   9
48K sleep   14:54  0.09  0.09 dtgreet

You need to do a bit more work to get the result you wanted.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question