On Sep 12, 2006, at 10:28 PM, Owen Cook wrote:
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`;
I just tried that and let it run in cron but there's no difference in
output. I still get "1"s in cron and process counts from the command
line.
Ooops, how about the full path to grep as well!
my $httpsd_count = `/usr/bin/ps -aux | /usr/bin/grep -c httpsd`;
my $mysqld_count = `/usr/bin/ps -aux | /usr/bin/grep -c mysqld`;
Tried adding the full path to grep and it just gets worse:
my $httpsd_count = `/bin/ps -aux | /usr/bin/grep -c httpsd`;
my $mysqld_count = `/bin/ps -aux | /usr/bin/grep -c mysqld`;
(on my machine, ps is in /bin)
cron:
2006-08-12 22:30:20 httpsd NOT RUNNING mysqld NOT RUNNING
2006-08-12 22:32:20 httpsd NOT RUNNING mysqld NOT RUNNING
2006-08-12 22:34:20 httpsd NOT RUNNING mysqld NOT RUNNING
command line:
2006-08-12 22:34:41 httpsd 20 mysqld 31
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>