in reply to Getting Process ID from process name
use strict; use warnings; my @PS_CMD=`ps -e`; my @badpid; my $count=0; $|++; for $_ (@PS_CMD) { chomp; ## get rid of trash ## next if /<defunct>/; s/^\s+//g; s/\s/,/g; s/,$//g; s/^,//g; s/(,)+/,/g; s/\s//g; next unless /^\d+/; ## End of trash collection ## my ($pid, $tty, $time, $cmd) = split(/,/, $_); my ($min, $sec) = split(/:/, $time); # change the $min > ## to change the # threshold at which we will be warned # change $cmd eq "<COMMAND>" to change # the command we "grep" for. Check the # output of `ps -e` for an example. if ( $cmd eq "YOUR_COMMAND" and $min > 200 ) { $count++; push (@badpid, $pid); } } my $pids=join(', ', @badpid); if ( $count > 0 ) { send_mail($pids) }
|
|---|