-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathensureSyslogEntry
executable file
·58 lines (53 loc) · 1.66 KB
/
ensureSyslogEntry
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
set -e # terminate on error
LOG_LDM=${1?LDM logging facility not set}
SYSLOG_CONF=${2?System logging configuration-file not set}
LDM_LOGFILE=${3?LDM log file pathname not set}
# Modifies a syslog-ng.conf(5) file.
#
modifySyslogNg() {
sed "s/\(and not facility([^)]*\))/\1,$LOG_LDM)/" "$SYSLOG_CONF" \
>"$SYSLOG_CONF".new
cat >>"$SYSLOG_CONF".new <<EOF
# Unidata LDM:
destination d_ldm { file("$LDM_LOGFILE"); };
filter f_ldm { facility($LOG_LDM); };
log { source(s_sys); filter(f_ldm); destination(d_ldm); };
EOF
cp "$SYSLOG_CONF" "$SYSLOG_CONF".old
mv -f "$SYSLOG_CONF".new "$SYSLOG_CONF"
}
# Modifies a syslog.conf(5) or rsyslog.conf(5) file.
#
modifySyslog() {
if fgrep $LOG_LDM.none "$SYSLOG_CONF" >/dev/null; then
cp "$SYSLOG_CONF" "$SYSLOG_CONF".new
else
awk '
{print}
NF >= 2 && ($1 ~ /\.none/ || $2 ~ /\/var\/log\/messages/ ||
$2 ~ /\/var\/log\/syslog/) {
print "'$LOG_LDM'.none " $2;
}' "$SYSLOG_CONF" >"$SYSLOG_CONF".new
fi
if grep "^$LOG_LDM\." "$SYSLOG_CONF" >/dev/null; then
: true
else
echo >>"$SYSLOG_CONF".new
echo '# Unidata LDM:' >>"$SYSLOG_CONF".new
echo "$LOG_LDM.* $LDM_LOGFILE" >>"$SYSLOG_CONF".new
fi
if cmp -s "$SYSLOG_CONF" "$SYSLOG_CONF".new; then
rm "$SYSLOG_CONF".new
else
cp "$SYSLOG_CONF" "$SYSLOG_CONF".old
mv -f "$SYSLOG_CONF".new "$SYSLOG_CONF"
fi
}
if fgrep "$LDM_LOGFILE" "$SYSLOG_CONF" >/dev/null; then
: true
else
case "$SYSLOG_CONF" in
*syslog-ng*) modifySyslogNg;;
*) modifySyslog;;
esac
fi