-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathservice_checker.sh
40 lines (33 loc) · 1.01 KB
/
service_checker.sh
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
#!/bin/bash
#sys_watch_checker.sh
#make sure a process is always running.
export DISPLAY=:0 #needed if you are running a simple gui app.
process="${1:-auditd}"
service="${2:-auditd}"
makerun="${3:-/sbin/auditd}"
grep_key="${4:-running}"
EMAIL="[email protected]"
if ps ax | grep -v grep | grep -w $process > /dev/null
then
echo "$process process is working.."
else
process="audit"
subject="Subject:$process is down"
to="To:[email protected]"
from="From:[email protected]"
body="$process is down. Trying to restart $process.."
echo -e "$to\n$from\n$subject\n$body" | sendmail -t $to
$makerun &
fi
if service $service status | grep $grep_key > /dev/null
then
echo "$service service is running"
else
subject="Subject:$service is down"
to="To:[email protected]"
from="From:[email protected]"
body="$service is down. Trying to restart $service.."
echo -e "$to\n$from\n$subject\n$body" | sendmail -t $to
service $service restart
fi
exit