4 STATUS=/var/cache/dsa/nagios/apt
5 SLEEP_MAX=$(( 15 * 60 ))
6 MAX_AGE=$(( 23 * 60 * 60 ))
8 # we want to run if any of the following things is true
9 # - we have never run before
10 # - var/lib/dpkg/status has been touched since the last run
11 # - var/cache/apt/pkgcache.bin has been touched since the last run
12 # - our last run ended with 'apt-get update failed'
13 # - our last run has been more than MAX_AGE (23hrs) ago
18 [ -e "$STATUS" ] || return $run
19 [ /var/lib/dpkg/status -nt "$STATUS" ] && return $run
20 [ /var/cache/apt/pkgcache.bin -nt "$STATUS" ] && return $run
21 grep "apt-get update failed" "$STATUS" > /dev/null && return $run
24 last_mod=`stat -c "%Y" "$STATUS"`
26 age=$(( $now - $last_mod ))
27 [ "$age" -gt "$MAX_AGE" ] && return $run
32 # do stuff only when required, or when asked to
33 if [ "${1:-""}" != "-f" ] ; then
37 # sleep if called non-interactively
38 if [ -z "$TERM" -o "$TERM" = "dumb" ]; then
39 sleep $(( $RANDOM % $SLEEP_MAX ))
42 # run apt-get update, retry a few times if it fails
44 while [ "$count" -lt "$UPDATE_RUNS" ]; do
45 apt-get update -qq >/dev/null >&2
46 if [ "$?" = "0" ]; then break; fi
47 sleep $(( $RANDOM % 600 ))
48 count="$(( $count + 1 ))"
50 if [ "$count" -ge "$UPDATE_RUNS" ]; then
52 echo "apt-get update failed") > "$STATUS"
56 # run the apt check itself
58 trap "rm -f '$tmp'" exit
59 #/usr/share/dsa/apt-status-check --noupdate --timeout=600 > "$tmp"
60 /usr/lib/nagios/plugins/dsa-check-packages > "$tmp"
76 (echo "$st"; cat "$tmp") > "$STATUS"