--- /dev/null
+#!/bin/sh
+
+failed() {
+ echo "$@" >&2
+ exit 1
+}
+
+log() {
+ [ "$VERBOSE" = "1" ] && echo "$@"
+}
+
+checkDNS() {
+ log "Check DNS lookup for '$1'."
+ if ! host "$1" 8.8.8.8 > /dev/null; then
+ failed "DNS lookup at 8.8.8.8 for '$1' failed."
+ fi
+}
+
+checkWebserver() {
+ log "Check web server at '$1'."
+ if ! curl -s "$1" > /dev/null; then
+ failed "Failed to retrieve website '$1'."
+ fi
+}
+
+checkMailserver() {
+ log "Check mail server at '$1'."
+ if ! echo "quit" | nc "$1" 587 | grep -m1 "^220 $1" > /dev/null; then
+ failed "Checking mail server '$1' failed."
+ fi
+}
+
+checkDiskfilling() {
+ log "Check disk filling at '$1'."
+ DF=$(ssh aristoteles.sthu.org "df -h | grep /$ | grep -o '[0-9]*%' | head -c -2")
+ if [ -n "$DF" ] && ! [ $DF -lt 80 ]; then
+ failed "Checking disk filling at '$1' failed."
+ fi
+}
+
+checkInternet() {
+ sleep 10
+ if ! host 8.8.8.8 8.8.8.8 > /dev/null; then
+ log "We do not appear to be connected to the internet."
+ exit 0
+ fi
+}
+
+
+usage() {
+ cat << EOF
+Usage:
+ $0 [OPTIONS]
+ $0 -h
+
+OPTIONS:
+ -h Show this text.
+ -v Print verbose output.
+ -a ADDRESS Check DNS (reverse) lookup.
+ -w ADDRESS Check webserver.
+ -m ADDRESS Check mailserver.
+ -d ADDRESS Check disk filling.
+EOF
+}
+
+source $HOME/.profile-sshagent
+VERBOSE=1
+checkInternet
+
+VERBOSE=0
+while getopts "vha:w:m:d:" OPTION; do
+
+ case "$OPTION" in
+ h)
+ usage
+ exit
+ ;;
+ v)
+ VERBOSE=1
+ ;;
+ a)
+ checkDNS $OPTARG
+ ;;
+ w)
+ checkWebserver $OPTARG
+ ;;
+ m)
+ checkMailserver $OPTARG
+ ;;
+ d)
+ checkDiskfilling $OPTARG
+ ;;
+ esac
+done
+
+
+
+