-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcmd.sh
executable file
·101 lines (79 loc) · 2.74 KB
/
cmd.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
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/usr/bin/env bash
#set -x
set -e
trap "killall rsyslog arpwatch nullmailer-send; exit 1" TERM
if [[ -z $ARPWATCH_NOTIFICATION_EMAIL_TO ]]; then
echo "env ARPWATCH_NOTIFICATION_EMAIL_TO missing"
exit 1
fi
if [[ -z $ARPWATCH_NOTIFICATION_EMAIL_FROM ]]; then
echo "env ARPWATCH_NOTIFICATION_EMAIL_FROM missing"
exit 1
fi
if [[ -z $ARPWATCH_NOTIFICATION_EMAIL_SERVER ]]; then
echo "env ARPWATCH_NOTIFICATION_EMAIL_SERVER missing"
exit 1
fi
COMMAND="arpwatch -u arpwatch -a -p"
if [[ "x$ARPWATCH_DEBUG" == "xyes" ]]; then
COMMAND="${COMMAND} -d"
fi
if [[ "x$ARPWATCH_INTERFACE" != "x" ]]; then
COMMAND="${COMMAND} -i ${ARPWATCH_INTERFACE}"
fi
COMMAND="${COMMAND} -m ${ARPWATCH_NOTIFICATION_EMAIL_TO}"
NULLMAILER_REMOTE="$ARPWATCH_NOTIFICATION_EMAIL_SERVER smtp"
if [[ "x$ARPWATCH_NOTIFICATION_EMAIL_SERVER_ENCRYPTION" == "xnone" ]]; then
# skipping
NULLMAILER_REMOTE="$NULLMAILER_REMOTE"
elif [[ "x$ARPWATCH_NOTIFICATION_EMAIL_SERVER_ENCRYPTION" == "xstarttls" ]]; then
NULLMAILER_REMOTE="$NULLMAILER_REMOTE --starttls"
else
NULLMAILER_REMOTE="$NULLMAILER_REMOTE --ssl"
fi
if [[ ! -z $ARPWATCH_NOTIFICATION_EMAIL_SERVER_PORT ]]; then
NULLMAILER_REMOTE="$NULLMAILER_REMOTE --port=$ARPWATCH_NOTIFICATION_EMAIL_SERVER_PORT"
fi
if [[ ! -z $ARPWATCH_NOTIFICATION_EMAIL_SERVER_USER ]]; then
NULLMAILER_REMOTE="$NULLMAILER_REMOTE --user=$ARPWATCH_NOTIFICATION_EMAIL_SERVER_USER"
fi
if [[ ! -z $ARPWATCH_NOTIFICATION_EMAIL_SERVER_PASS ]]; then
NULLMAILER_REMOTE="$NULLMAILER_REMOTE --pass=$ARPWATCH_NOTIFICATION_EMAIL_SERVER_PASS"
fi
DIR="/var/lib/arpwatch"
if ! su - arpwatch -s /bin/sh -c "test -w '$DIR'" ; then
echo "$DIR is not writable by arpwatch user. chmod it 777."
exit 1
fi
IFS='@' read -ra FROM <<< "$ARPWATCH_NOTIFICATION_EMAIL_FROM"
export NULLMAILER_FLAGS="fst"
export NULLMAILER_USER="${FROM[0]}"
export NULLMAILER_HOST="${FROM[1]}"
export NULLMAILER_NAME="Arpwatch ($HOSTNAME)"
echo $NULLMAILER_REMOTE > /etc/nullmailer/remotes
/etc/init.d/nullmailer start
touch /var/lib/arpwatch/arp.dat
touch /var/lib/arpwatch/arp.dat.new
chmod -R 777 /var/lib/arpwatch
# run rsyslogd to catch cron messages
rm -f /var/run/rsyslogd.pid
rsyslogd -f /rsyslog.conf
if [[ "x$ARPWATCH_DEBUG" == "xyes" ]]; then
exec ${COMMAND}
else
${COMMAND}
fi
while sleep 10; do
ps aux |grep rsyslog |grep -q -v grep
PROCESS_1_STATUS=$?
ps aux |grep arpwatch |grep -q -v grep
PROCESS_2_STATUS=$?
ps aux |grep nullmailer-send |grep -q -v grep
PROCESS_3_STATUS=$?
# If the greps above find anything, they exit with 0 status
# If they are not both 0, then something is wrong
if [ $PROCESS_1_STATUS -ne 0 -o $PROCESS_2_STATUS -ne 0 -o $PROCESS_3_STATUS -ne 0 ]; then
echo "One of the processes has already exited."
exit 1
fi
done