|
Have given it many attempts to fix….but
now need help.. From: Smith, Derek I am getting the following error yet the script is doing
what I need it to do restart a process: Use of uninitialized value at
/usr/local/admin/named_monit.pl line 71 (#1) (W) An undefined value was used as if it were
already defined. It was interpreted as a "" or a 0, but maybe
it was a mistake. To suppress this warning assign an initial value to your
variables. ps: wrong PID number -o ps: Unknown option (vsz). Did not close FH ps at
/usr/local/admin/named_monit.pl line 86. Did not close FH pso at
/usr/local/admin/named_monit.pl line 87. Here is my code as attached, but please excuse the Perl
version….. 5.005_03 Thank you Derek Derek Bellner Smith Unix Systems Engineer Cardinal Health
Dublin, _________________________________________________ This message is for the designated recipient only and may contain privileged, proprietary, or otherwise private information. If you have received it in error, please notify the sender immediately and delete the original. Any other use of the email by you is prohibited. Dansk - Deutsch - Espanol - Francais - Italiano - Japanese - Nederlands - Norsk - Portuguese - Svenska: www.cardinalhealth.com/legal/email |
#!/usr/contrib/bin/perl
# Derek B. Smith
require 5.00503;
use strict;
#use warnings;
use diagnostics;
$ENV{"PATH"} = qq(/usr/sbin:/usr/bin:/bin:/sbin);
$ENV{UNIX95} = 1;
delete @ENV{qw (IFS CDPATH ENV KSH_ENV) };
my @arry = ();
my $oncall = qq/[EMAIL PROTECTED]/;
my $log = qq(/var/adm/named.log);
use constant VSZ => 63000;
##-- BEGIN ROUTINES --##
my $overide = $SIG{__DIE__}; ## get error handler currently assigned 2 die
$SIG{__DIE__} =
sub {
my $error = shift; ## error now holds the mesg passed to die
$overide->($error) if (ref $overide);
print LOG ($error);
};
sub dateme {
my ($hour,$min,$month,$day,$year) = (localtime)[2,1,4,3,5];
sprintf ("%02d:%02d %02d/%02d/%02d\n", $hour,$min,$month+1,$day,
($year % 100));
}
sub namedchk {
if (scalar @arry == 1) {
print LOG "restarting named on dubdns02\n";
print LOG "named process count:\t", scalar @arry,"\n";
print LOG dateme(),"\n";
system ("/sbin/init.d/named stop");
system ("/usr/bin/kill -9 $arry[0]");
sleep 5;
system ("/sbin/init.d/named start");
print LOG "named process count after restart:\t", scalar
@arry,"\n",dateme(),"\n";
}
elsif (scalar @arry > 1) {
print LOG "there is more than 1 named process on dubdns02";
print LOG dateme();
system ("echo named dubdns02|mailx -s named $oncall");
}
}
##-- BEGIN MAIN --##
open (LOG, ">>$log") or warn "unable to open log $!";
open (PS, "ps -ef|grep /usr/sbin/[n]amed |") or die "not spawn ps $!";
for (;<PS>;) {
push @arry, (split)[1];
}
if (scalar @arry < 1) {
print LOG "named was not running, now restartng\n", dateme();
system ("echo named dubdns02|mailx -s named $oncall");
system ("/sbin/init.d/named start");
}
open (PSO, "ps -p$arry[0] -o vsz |") or die "unable to spawn ps -p $!";
##-- LINE 71 --##
foreach (<PSO>) {
if (/\d+/) {
if ($_ >= VSZ) {
print LOG "named vsz reached over 60mb,now stopping &
starting\n";
print LOG dateme(),"\n";
namedchk();
}
else {
exit 1;
}
}
}
close (PS) or warn "Did not close FH ps $!";
close (PSO) or warn "Did not close FH pso $!";
close (LOG) or warn "Did not close FH log $!";
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>
