#!/bin/bash # ## apt-check ## ## A simple shell script to check debian machines for updates using the apt-get ## utility. If there are no updates available and no error occurred, there is ## also no output. This is for easy use in /etc/crontab ## ## Explanation: If you start a script by using /etc/crontab, every output is ## sent to you by mail. If there is no output, there is also no mail. So you ## can use this script in /etc/crontab and if anything happend you will ## receice a mail. ## ## Here is a example how to include this script to /etc/crontab: ## 0 */2 * * * root /usr/local/bin/apt-check ## ## This script has NO parameters. ## ## Exit-Code 0 = No updates available (no output - for use in cronjob) ## Exit-Code 1 = New updates available (see output, STDOUT) ## Exit-Code 2 = An error occurred (see output, STDOUT) ## ## ## Configuration ## # The given message is included in every output. You can use it to identify # different machines (if you have a log), when you get a message from the # script MACHINE="Server: bierhasser.dyndns.org" # First line of any output # Dont chance if apt-get is located in /usr/bin (this is default). # use 'whereis apt-get' to check. APTGETCMD="/usr/bin/apt-get" # Pfad und Name des apt-get binary ## ---------------------------------------------------------------------------- ## DON'T EDIT ANYTHING BELOW THIS LINE! DON'T EDIT ANYTHING BELOW THIS LINE! ## ---------------------------------------------------------------------------- # # UPDATE # export LANG=C APTOUTPUT=`$APTGETCMD update 2>&1` EXITCODE=$? if [[ "$EXITCODE" -ne "0" ]] then echo "$MACHINE"; echo "WARNING: There were errors while updating the package list." echo " Possibly there is no response from an update server" echo " or any other failure was happening." echo echo "----------------------------------------------------------------" echo "$APTOUTPUT" echo "----------------------------------------------------------------" exit 2 fi # # DIST-UPGRADE # APTOUTPUT=`$APTGETCMD -s -u safe-upgrade 2>&1` PACKAGECOUNT=`echo "$APTOUTPUT" | grep "packages upgraded" | perl -pe "s/^([0-9]+).*$/\1/g" 2>&1` if [[ "$PACKAGECOUNT" -ne "0" ]] then echo "$MACHINE"; echo "Updates are available. Please install them as soon as possible." echo echo "----------------------------------------------------------------" echo "$APTOUTPUT" echo "----------------------------------------------------------------" exit 1 fi