Operating System - HP-UX
1752598 Members
5076 Online
108788 Solutions
New Discussion юеВ

Re: top command - scripting....

 
BrianDoyle
Trusted Contributor

top command - scripting....

I know 'top' is an interactive command but was hoping there is a way to add it to a script that runs for 10 seconds then terminates and the script continues.
Any thoughts?
6 REPLIES 6
Mel Burslan
Honored Contributor

Re: top command - scripting....

It is possible using the -s and -d switches at the command line.

-s
________________________________
UNIX because I majored in cryptology...
James R. Ferguson
Acclaimed Contributor

Re: top command - scripting....

Hi:

To add to Mel's suggestions, if you want to capture the output of 'top' into a file for subsequent use, be sure to use the '-f filename' switch. If you don't your output file (from simple redirection) would otherwise contain terminal control characters for cursor positioning --- not what you want.

Regards!

...JRF...
Hakki Aydin Ucar
Honored Contributor

Re: top command - scripting....

-quote from Duncan (he did it for disk IO), I liked it:

Create a file (I called it /tmp/cpu_top) with the following contents:

Print "----------CPU USAGE:"
cpu loop {
PRINT "CPU # ", bycpu_id, " used ", bycpu_cpu_total_util, "% CPU"
}

Then reference this from glance with a suitable interval:

glance -aos /tmp/cpu_top -j 10

it just show every 10 seconds all CPU(s) usage. Of course it is flexible to create more fields. .

Laurent Menase
Honored Contributor

Re: top command - scripting....

Hakki is right, use glance adviser mode gives much more accurate results.

- top works on sampled metrics, when glance is using accurate metrics-.
Hakki Aydin Ucar
Honored Contributor

Re: top command - scripting....

>Laurent:

Yes you are right indeed, Glance is better when it comes to accuracy, different is in method used to measurement. I recommend to check this link about glance v.s. top

http://www.unix.com/hp-ux/50084-glanceplus-v-s-top.html
Mel Burslan
Honored Contributor

Re: top command - scripting....

Hakki & Laurent,

You are overlooking one important matter: MONEY!

top is free to use whereas glance is costly. And all you need to see who is the top CPU hog for few seconds, top does the job comparably well. Yes, if you have a large shop with gazillion machines and you need to be on top of performance problem and what-not all the time, glance is worth it's manuals weight in gold, but for a shop with not much of a budget, let alone a home user with one or two hpux machines setup for god knows what, glance is overkill.

________________________________
UNIX because I majored in cryptology...