summaryrefslogtreecommitdiff
path: root/doalogwatch.in
blob: a70e01a01744e005108a9b189482b182d6496fe1 (plain)
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
#!/bin/bash

# doalogwatch, part of logwatch-extra version #VERSION#

set -e

abWannNaechstesMal="$(date +%F)"
lmDatei="#CACHEDIR#/logwatch/letzteMeldung"
warteAufFile="#WAITDIR#/logwatch"

[ ! -r "${lmDatei}" ] && \
  echo '1970-01-01' > "${lmDatei}"

[ "${abWannNaechstesMal}" == "$(cat "${lmDatei}")" ] && \
  exit 0

[ -r "${warteAufFile}" ] && \
  ps aux | \
    awk '{print $2" "$(NF)}' | \
    grep -q "^\s*$(cat "${warteAufFile}") \(\S*/\)\?doalogwatch\$" && \
  exit 0

if [ -d "${warteAufFile%/*}" ]; then
  echo $$ > "${warteAufFile}"
fi

[ -r #ETCDIR#/backup.conf ] && \
  . #ETCDIR#/backup.conf

warten=true
until ! ${warten}
do

  warten=false

  [ $(cat /proc/uptime | cut -d ' ' -f 1 | sed "s/\..*\$//") -le 300 ] && \
    warten=true

  # check for currently running backups
  ps aux | \
    grep -v "\sgrep\s" | \
    grep -q "\s\(#BINDIR#/\)\?backup\s" && \
    warten=true
  if [ -r #ETCDIR#/backup.conf ]
  then
    for i in 1 2
    do
      for id in "${!backups[@]}"
      do
        [ -e "#TMPDIR#/${id}.pid" ] && \
          warten=true
      done
      sleep 1
    done
  fi

done

logwatch --archives --range "between $(cat "${lmDatei}") and yesterday"

echo "${abWannNaechstesMal}" > "${lmDatei}"

rm -f ${warteAufFile}