From 049ef89f61d90b253c7dfdddde830054c385b78a Mon Sep 17 00:00:00 2001 From: Holger Weiss Date: Sun, 29 Dec 2013 00:39:07 +0100 Subject: Let Cron check our FTP mirrors Add a daily job that updates a timestamp file in our download area and checks whether the FTP mirrors fetched the one from yesterday. diff --git a/bin/check-mirrors b/bin/check-mirrors new file mode 100755 index 0000000..ed37c38 --- /dev/null +++ b/bin/check-mirrors @@ -0,0 +1,47 @@ +#!/bin/sh +# +# Copyright (c) 2013 Nagios Plugins Development Team +# +# Originally written by Holger Weiss . +# +# This file is free software; the Nagios Plugins Development Team gives +# unlimited permission to copy and/or distribute it, with or without +# modifications, as long as this notice is preserved. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY, to the extent permitted by law; without even the implied +# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + +set -e +set -u +umask 022 + +export PATH='/usr/local/bin:/usr/local/sbin:/bin:/sbin:/usr/bin:/usr/sbin' + +mirrors=' + ftp://ftp.fu-berlin.de/unix/network/nagios-plugins/ + ftp://ftp.lysator.liu.se/pub/nagios-plugins/ +' +prefix='/home/plugins' +myself=${0##*/} +download_dir="$prefix/web/download" +temp_dir=$(mktemp -d "/tmp/$myself.XXXXXX") + +trap 'rm -rf "$temp_dir"' EXIT + +cd "$temp_dir" +date -d 'yesterday' '+%F' >'expected' +for mirror in $mirrors +do + url="${mirror%/}/timestamp" + + if curl -s -S -O "$url" >'curl.log' 2>&1 + then + cmp -s 'expected' 'timestamp' \ + || echo >&2 "$mirror is outdated ($(cat 'timestamp'))." + else + echo >&2 "Cannot fetch $url: $(cat 'curl.log')" + fi +done +cd "$OLDPWD" +date '+%F' >"$download_dir/timestamp" diff --git a/etc/crontab b/etc/crontab index 86bba49..0339f69 100644 --- a/etc/crontab +++ b/etc/crontab @@ -5,3 +5,4 @@ MAILTO=admin@monitoring-plugins.org # */10 * * * * $HOME/bin/git-mirror $HOME/repositories/nagios-*.git +44 4 * * * $HOME/bin/check-mirrors -- cgit v0.10-9-g596f