Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Capturing information from a top script

Posted on 2004-09-02
5
Medium Priority
?
462 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 400 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 1600 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

Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

Question has a verified solution.

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

Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

660 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