in reply to loop control

The way you assign a number as a key for each element of %prolist seems pointless, if I read your intentions correctly. Here's what you're probably trying to do:
#!/usr/bin/perl -w use strict; my @required = qw( CMD /bin/sh rds SysExec /oasis/bin/sysmenu /oasis/bin/TS_TextSrvcs ); # invoke ps -a using backticks, read result into a list # for each line, split on whitespace, keep 3rd element # return a list of element => undef pairs my %procs = map { (split ' ')[3], undef } qx/ps -a/; # %procs now has a key named after each process # values are empty, mere existence of the keys suffices # now for each required process, # check if it has an entry in the hash of running procs my @missing = grep !exists $procs{$_}, @required; # print the resulting list of missing processes print map "NF: $_\n", @missing;
Or more condensed:
#!/usr/bin/perl -w use strict; my %procs = map { (split ' ')[3], undef } qx/ps -a/; print map "NF: $_\n", grep !exists $procs{$_}, qw( CMD /bin/sh rds SysExec /oasis/bin/sysmenu /oasis/bin/TS_TextSrvcs );
Note however that most every variant of ps has some switch to make it output only process names, in which case the split becomes superfluous. Assuming GNU ps:
my %procs = map { chomp; $_ => undef } qx/ps -a ho comm/;

This is much more robust, as it avoids the need to parse an external program's output.

All that said and done, if you want to monitor your system, you should not reinvent the wheel. Nagios, mon and Big Brother will do many things for you. Don't waste your time.

Makeshifts last the longest.

Replies are listed 'Best First'.
Re: Re: loop control
by maxl90 (Sexton) on Feb 05, 2003 at 19:01 UTC
    Thanks a lot guys i'v implimented a few ideas and things are running very smoothly now.