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!