#get running processes, users, 1 min load average, total mem, free mem (ultimately display free mem %) my @raw=`top -b -n 1`; my %stats; @stats{'users','load','tmem','fmem','runproc'} = (); my $its=0; foreach my $line (@raw){ if ($line =~ /up\s.+\s(\d+)\suser.+\s+load\saverage:\s+(\d+\.\d{2}),/){ $stats{users}=$1; $stats{load}=$2; } elsif ($line =~ /(?:Tasks|processes):.+\s+(\d+) running/i){ $stats{runproc}=$1; } elsif ($line =~ /^Mem:\s+(\d+)k\s+(?:total|av),.+used,\s+(\d+)k\s+free/){ $stats{tmem}=$1; $stats{fmem}=$2; } $its++; my $uds=0; foreach (values(%stats)){ defined or ++$uds; } if ($uds){ print "Still $uds undefined values"; } else{ print "I'm done!"; last; } } ## end foreach my $line (@raw) print "I looped $its times to collect the data I need from $host";