Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Obtaining data from the top command via a pipe

by AReed (Pilgrim)
on Aug 08, 2005 at 21:46 UTC ( [id://482040]=note: print w/replies, xml ) Need Help??


in reply to Obtaining data from the top command via a pipe

In batch mode, one iteration of top won't display the information that you are interested in. Add the -d2 option to run a couple of iterations, and the second should include the CPU info.
#!/usr/bin/perl use warnings; use strict; open (PIPE, "/usr/local/bin/top -b -d2 |") or die "Cannot open top: $! +"; while (<PIPE>) { if (/^CPU/) { print; last; } } close(PIPE); exit(0);
I tested this on a Sun-Fire-280 running Solaris 9 and I am not a Unix guru so your mileage may vary. Best of luck.

Updated: removed temporary variable for input line.

Replies are listed 'Best First'.
Re^2: Obtaining data from the top command via a pipe
by tc1364 (Beadle) on Aug 10, 2005 at 14:03 UTC
    Thank you, this really helps allot!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://482040]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (5)
As of 2024-04-23 23:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found