Page 1 of 1

creating a perl Script to check service status

Posted: Wed Oct 11, 2017 10:32 pm
by camacho12th
Does anyone have a sample perl script for monitoring a service within /etc/int.d?

I've struggled to find one already made and now I must learn how to create one. This would really help me get my feet firmly on the ground.

Basically, I have an asterisk Service on a remote linux server that I want to make sure is running. If not, then generate a warning or critical.

Thank you greatly

Re: creating a perl Script to check service status

Posted: Thu Oct 12, 2017 11:51 am
by eloyd
Just curious why you're not using the default "check_init_service" script to do that?

Re: creating a perl Script to check service status

Posted: Thu Oct 12, 2017 1:05 pm
by tacolover101
eloyd wrote:Just curious why you're not using the default "check_init_service" script to do that?
perl 4 lyfe. this is a good question though.

Code: Select all

$s=(`service $ARGV[0] status`);
if ($s =~ '(running)') {
   $val1="is";
   $val2=1;
   }
else {
   $val1="is not";
   $val2=0;
   }
you'll need to get creative with how you leverage $ARGV[0] in a print command to define ok / warning / etc. could be written better, but there's a framework. logic could be written better, too.

Re: creating a perl Script to check service status

Posted: Thu Oct 12, 2017 2:32 pm
by kyang