On Tue, 12 Sep 2006, James Marks wrote:

> Hi folks,
> 
> I don't know if this is a Perl or UNIX problem and I'm hoping you can 
> help me figure that out.
> 
> I wrote a script that checks to see if the httpsd and mysqld processes 
> are running on my server and to log the results of those tests.
> 
> When I run the script from the command line, the script prints to a log 
> file the number of each of those processes that are running at the time 
> of the script execution. When I run the same script from cron, however, 
> it only prints a "1" for httpsd and mysqld.


<snip>> 
> 
> 
> Here's the cron entry:
> 
> */15    *       *       *       *       perl 
> /home/james/code/cron_code/httpsd_mysqld_check.pl
> 
> 
> 
> Here's the script:
> 
> #!/usr/bin/perl
> 
> use warnings;
> use strict;
> 
> my $log_file = '/home/james/code/cron_code/httpsd_mysqld_log_file';
> 
> open FILE_OUT, ">> $log_file"
>      or die "Cannot open log file: $!";
> 
> select FILE_OUT;
> 
> (my $month, my $day, my $year, my $hour, my $minute, my $second) = 
> (localtime)[4, 3, 5, 2, 1, 0];
> 
> printf("%04s-%02s-%02s %02d:%02d:%02d ", $year+1900, $month, $day, 
> $hour, $minute, $second);
> 
> my $httpsd_count = `ps -aux | grep -c httpsd`;
> my $mysqld_count = `ps -aux | grep -c mysqld`;
> 
> chomp($httpsd_count);
> chomp($mysqld_count);
> 
> my $httpsd_msg = '';
> my $mysqld_msg = '';
> 
> if ($httpsd_count > 0) {
>      print "httpsd $httpsd_count ";
> }
> else {
>      print "httpsd NOT RUNNING ";
> }
> 
> if ($mysqld_count > 0) {
>      print "mysqld $mysqld_count ";
> }
> else {
>      print "mysqld NOT RUNNING ";
> }
> 
> print "\n";
> 
> close FILE_OUT;
> 


I suspect that your env includes the path to "ps"

For cron you would need the full path

Try 
 my $httpsd_count = `/usr/bin/ps -aux | grep -c httpsd`;
 my $mysqld_count = `/usr/bin/ps -aux | grep -c mysqld`;

or wherever ps is



Owen


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to