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
35 # sleep if called non-interactively
36 if [ -z "$TERM" -o "$TERM" = "dumb" ]; then
37 sleep $(( $RANDOM % $SLEEP_MAX ))
40 # run apt-get update, retry a few times if it fails
42 while [ "$count" -lt "$UPDATE_RUNS" ]; do
44 if [ "$?" = "0" ]; then break; fi
45 sleep $(( $RANDOM % 600 ))
46 count="$(( $count + 1 ))"
48 if [ "$count" -ge "$UPDATE_RUNS" ]; then
50 echo "apt-get update failed") > "$STATUS"
54 # run the apt check itself
56 trap "rm -f '$tmp'" exit
57 #/usr/share/dsa/apt-status-check --noupdate --timeout=600 > "$tmp"
58 /usr/lib/nagios/plugins/dsa-check-packages > "$tmp"
74 (echo "$st"; cat "$tmp") > "$STATUS"