use strict;
use warnings;

use Email::Stuff;
use Proc::ProcessTable;
 
my $pt    = Proc::ProcessTable->new( 'cache_ttys' => 1 );
my $found = 0;

foreach my $process ( @{ $pt->table } ) {
    my $cmndline = $process->cmndline;
    if ( $cmndline =~ /apache/ ) {
        $found++;
    }
}

if ($found) {
    open my $fh, '>', 'perl_script.log' or die "Can't open file: $!\n";
    print {$fh} scalar localtime time, ": Found Apache running $found times\n";
    close $fh or die "Can't close file: $!\n";
} else {
    # debian/ubuntu
    system "/etc/init.d/apache start";

    # redhat/fedora/centos
    #system "/etc/init.d/httpd start

    Email::Stuff->from     ('admin@me' )
                ->to       ('you@dumy' )
                ->text_body('Apache is down, fools!')
                ->send;
}

my $random_num = rand(90) + 10; # rand() already runs srand()

