Here a better formatted version.

#!/usr/bin/perl
@jails = `jls`;
$title = shift @jails;
chomp $title;
print $title . "\t\t%CPU\t%MEM\n";
foreach (@jails)
{
  my ($jid) = /\s+(\S+)\s/;
  @jexec = `jexec $jid ps -afxu`;

  @mem = map {/\S+\s+\S+\s+\S+\s+(\S+)\s/} @jexec;
  shift @mem;
  $tot_mem = 0;
  foreach (@mem) { $tot_mem = $tot_mem + $_; }

  @cpu = map {/\S+\s+\S+\s+(\S+)\s/} @jexec;
  shift @cpu;
  $tot_cpu = 0;
  foreach (@cpu) { $tot_cpu = $tot_cpu + $_; }

  chomp $_;
  print $_ . "\t";
  printf('%4.1f', $tot_cpu);
  print "\t";
  printf ('%4.1f', $tot_mem);
  print "\n";
}

---------------
Philippe Lang
Attik System

Attachment: smime.p7s
Description: S/MIME cryptographic signature

Reply via email to