-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_long_running_procs.pl
More file actions
84 lines (83 loc) · 1.79 KB
/
check_long_running_procs.pl
File metadata and controls
84 lines (83 loc) · 1.79 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/usr/bin/perl -w
use Getopt::Std;
getopts('w:c:');
unless ($opt_w && $opt_c || $opt_h)
{
print "Unknown - ";
&Help;
exit 3;
}
if ($opt_h)
{
&Help;
exit 0;
}
$warn = $opt_w;
$crit = $opt_c;
$w = $c = 0;
@processes = `ps -eo 'time pid' | sort`;
for ($i=0; $i <= $#processes; $i++)
{
chomp $processes[$i];
if ($processes[$i] =~ /-/)
{
(@days) = split(/-/, $processes[$i]);
(@pid) = split(/\s+/, $processes[$i]);
if ($days[0] >= $warn)
{
$warning{$pid[-1]} = $days[0];
$w++;
}
elsif ($days[0] >= $crit)
{
$critical{$pid[-1]} = $days[0];
$c++;
}
}
}
if ($c)
{
while (($key, $value) = each %critical)
{
print "The number of days process number $key has run is $value\n";
$elapsDays = getElapsDays($key);
if ($elapsDays - $value)
{
$c--;
}
}
if($c)
{
exit 2;
}
}
elsif($w)
{
while (($key, $value) = each %warning)
{
print "The number of days process number $key has run is $value\n";
$elapsDays = getElapsDays($key);
if ($elapsDays - $value)
{
$w--;
}
}
if($w)
{
exit 1;
}
}
else
{
exit 0;
}
sub getElapsDays
{
$process = shift;
$line = `ps -eo 'etime pid' | egrep $process | grep -v grep`;
@numOfDays = split (/-/, $line);
return $numOfDays[0];
}
sub Help
{
}