in reply to undefined question

If I'm totally off on that, can someone point me into the direction I need to go in to check for when something WON'T be there?

You're not totally off. You're looking right at it. If the process doesn't exist, you'll get nothing on standard output. Here's why.

while ( my $proc = <PROCS> ) { # if the grep filters out everything, this is a # zero-trip loop. }
You might have better luck with something like
my $found_one = 0; while ( my $proc = <PROCS> ) { ... $found_one = 1; } if ( $found_one ) { print "looks okay here\n"; } else { print "couldn't find $process\n"; }
Note also that you could do both of the greps in Perl, rather than launching additional external processes.

Replies are listed 'Best First'.
Re: Re: undefined question
by Anonymous Monk on Jun 09, 2003 at 04:53 UTC
    Thanks dws. Also informative. ONe thing though: I needed to make a small change.
    while ( my $proc = <PROCS> ) { ... $found_one = 1; } if ( $found_one ) { print "looks okay here\n"; found_one = 0; } else { print "couldn't find $process\n"; }
    W/o resetting the $found_one to 0, it would never alert me when the other processes (anything after 1) weren't running. As for the greps externally - I recall finding this in a perl tutorial many moons ago, and never learned it another way. Might you have a link that explains it internally?
      As for the greps externally - I recall finding this in a perl tutorial many moons ago, and never learned it another way. Might you have a link that explains it internally?

      You'd find that described under "regular expressions". As an example,

      open(PROCS, "ps -a | grep $process |"); while ( my $proc = <PROCS> ) { # ... }
      can be rewriten (assuming $process holds an alphanumeric string) as
      open(PROCS, "ps -a |"); while ( my $proc = <PROCS> ) { next if $proc !~ /$process/; # ... }
      Regular expressions are your friends. Learning about them pays off in many ways.

        I've actaully been playing w/ regular expressions a bit lately. I wouldn't have thoght of using them w/ this though - this is pretty easy, after I got over my initial hurdle. They're still a bit foreign, but after reading (and asking) here, I've gotten them to do some pretty helpful things. Again - thanks for the wisdom