#!/usr/bin/perl -w # # proccount.pl - enumerates the number of processes # for arbitrary commands (supplied as parameters). # Current command list: # "ps -eo cmd|awk '{print $1}'|sort|uniq" use strict; # cancel if no arguments exist if (!@ARGV) { exit 1; } my %command_counter; # initialize a counter for each command foreach (@ARGV) { $command_counter{$_} = 0; } # Go through process list and increment # command count if necessary foreach (split(/\n/,`ps -eo cmd|awk '{print \$1}'`)) { if ( exists($command_counter{$_}) ) { $command_counter{$_}++; } } # Write the values to an array # observing the correct order my @values; foreach (@ARGV) { push @values, $command_counter{$_}; } # Output print join(' ',@values);