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.



script output to log when run from the command line:

2006-08-12 21:10:20 httpsd 23 mysqld 33



script output to log when run from cron:

2006-08-12 21:11:05 httpsd 1 mysqld 1



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;



Any ideas on why the same script has different results when run from the command line vs. from cron?

Thanks,

James


--
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