-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_start_process.pl
39 lines (34 loc) · 1.31 KB
/
check_start_process.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/perl -w
my @services = ('service1', 'service2');
my @commands = ('start_service1_command', 'start_service2_command');
my $root_dir = '/path/to/script/log/';
my $logfile="$root_dir/check_process.log";
my $date=`date`;
chomp($date);
# ---------- open logfile --------------------------------------------
open(LOG, ">$logfile") or die "Can't open $logfile to write: $!";
print LOG "Monitor Started On $date!\n";
close(LOG);
# ---------- close logfile --------------------------------------------
$i=0;
foreach my $service (@services)
{
my $status = `ps ax | grep $service | grep -v grep`;
if (!$status) {
# ---------- open logfile --------------------------------------------
open(LOG, ">>$logfile") or die "Can't open $logfile to write: $!";
print LOG "Service $service is started ON $date!\n";
close(LOG);
print "Service $service is started ON $date!\n";
# ---------- close logfile --------------------------------------------
my $skcom = exec($commands[$i]);
}else {
# ---------- open logfile --------------------------------------------
open(LOG, ">>$logfile") or die "Can't open $logfile to write: $!";
print LOG "Service $service is running\n";
close(LOG);
# ---------- close logfile --------------------------------------------
print "Service $service is running\n";
}
$i++;
}