James Marks wrote: > > If I've correctly interpreted your suggested changes, the script now > reads: > > -- SCRIPT ------------------ > > #!/usr/bin/perl > > use warnings; > use strict; > > my $log_file = '/home/james/httpsd_mysqld.log'; > > open FILE_OUT, ">> $log_file" > or die "Cannot open log file: $!"; > > select FILE_OUT; > > my ( $second, $minute, $hour, $day, $month, $year ) = localtime; > > my $time = sprintf '%04d-%02d-%02d %02d:%02d:%02d', > $year + 1900, $month + 1, $day, $hour, $minute, $second; > > open PS, '-|', '/bin/ps', 'aux' or die "Cannot open pipe from ps: $!"; > > my ( $httpsd_count, $mysqld_count ); > > while ( <PS> ) { > $httpsd_count++ if /httpsd/; > $mysqld_count++ if /mysqld/; > } > > close PS or warn $! ? "Error closing ps pipe: $!" > : "Exit status $? from ps"; > > print $time, > ' httpsd ', $httpsd_count || 'NOT RUNNING', > ' mysqld ', $mysqld_count || 'NOT RUNNING', > "\n"; > > -- END SCRIPT ------------------ > > The line: > > open PS, '-|', '/bin/ps', 'aux' or die "Cannot open pipe from ps: $!"; > > returns an error on my Perl 5.6.1 machine (which I can't upgrade): > > "Can't use an undefined value as filehandle reference"
Perl's warning/error messages usually end with the file name and line number. Are you sure that that is the line the error is referring to? > even though "Programming Perl" says it should work in 5.6.1. (FTR, it > works fine in Perl 5.8.7) > > Any ideas as to why that might be? According to the documentation there are four ways you could write that: open PS, '-|', '/bin/ps', 'aux' or die "Cannot open pipe from ps: $!"; open PS, '-|' or exec '/bin/ps', 'aux' or die "Cannot open pipe from ps: $!"; open PS, '-|', '/bin/ps aux' or die "Cannot open pipe from ps: $!"; open PS, '/bin/ps aux |' or die "Cannot open pipe from ps: $!"; And the last one should work with any version of Perl on any platform so see if one of the other ways will work for you. (They all work fine for me on Linux.) Check the docs: perldoc perlport perldoc perl<your platform name> and they should have information on supported and unsupported features. John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>