Can you please assit me with obtaining the "CPU states: 91.7% idle, 6.8% user, 0.7% kernel, 0.8% iowait, 0.0% swap" line from the top command? Looking at man for top didn't help.
#!/usr/bin/perl open PIPE, "/usr/local/bin/top -b -n 3 |" or die "Cannot open"; my $output = join '', <PIPE>; close PIPE or die "Running top failed"; print "$output\n"; exit(0);
The output looks like the below currently.
load averages: 0.26, 0.24, 0.30 16:02:45 171 processes: 168 sleeping, 1 running, 1 zombie, 1 on cpu Memory: 1024M real, 767M free, 92M swap in use, 1732M swap free PID USERNAME THR PRI NICE SIZE RES STATE TIME CPU COMMAND 6451 pc2587 1 11 0 984K 704K sleep 0:26 5.36% br 5983 dw3586 1 48 0 984K 704K sleep 1:19 0.35% br 5962 dw3586 1 48 0 984K 704K sleep 1:39 0.35% br

Edited by Arunbear: Changed title from 'PIPE', as per Monastery guidelines; and added code tags around output.


In reply to Obtaining data from the top command via a pipe by tc1364

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.