├── README.md └── apt-update-mail.sh /README.md: -------------------------------------------------------------------------------- 1 | # Apt-update-mailer 2 | 3 | This is a bash script which can be ran from a cronjob. It mails which packages can be updated, the current version you have installed, the version you are updating to and (on an ubuntu system) an URL to the Ubuntu package archive with more info on the update. If there are no updates, you won't get an email. 4 | 5 | ## Example output: 6 | 7 | --- Updates for host: vps11.sparklingclouds.nl --- 8 | Date: 21.09.2012 9 | 10 | Total updates available: 44 11 | 12 | -- Package: apport -- 13 | Installed: 2.0.1-0ubuntu12 14 | Candidate: 2.0.1-0ubuntu13 15 | Package Information: http://packages.ubuntu.com/precise/apport 16 | -- End package apport -- 17 | 18 | -- Package: build-essential -- 19 | Installed: 11.5ubuntu2 20 | Candidate: 11.5ubuntu2.1 21 | Package Information: http://packages.ubuntu.com/precise/build-essential 22 | -- End package build-essential -- 23 | 24 | -- Package: dbus -- 25 | Installed: 1.4.18-1ubuntu1 26 | Candidate: 1.4.18-1ubuntu1.1 27 | Package Information: http://packages.ubuntu.com/precise/dbus 28 | -- End package dbus -- 29 | 30 | ## Installation 31 | 32 | Create a folder for the scripts (doesn't need to be root): 33 | 34 | mkdir ~/scripts 35 | 36 | Place the script there (or git clone the repo): 37 | 38 | nano ~/scripts/apt-update-mailer.sh 39 | 40 | Make it executable: 41 | 42 | chmox +x ~/scripts/apt-update-mailer.sh 43 | 44 | Add the cronjob: 45 | 46 | crontab -e 47 | # [ADD, CHECKS ONCE A DAY AT 01:01 AM] 48 | 1 1 * * * ~/scripts/updatemail.sh 49 | 50 | If you don't receive any emails it either means the script did not find any updates, or that your MTA is not setup correctly. Check /etc/aliases, the postfix/sendmail installation and the cron email address. 51 | 52 | ## Links 53 | 54 | [Page on raymii.org](https://raymii.org/cms/p_Ubuntu_update_mailer) 55 | -------------------------------------------------------------------------------- /apt-update-mail.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #Copyright (c) 2012 Remy van Elst 3 | #Permission is hereby granted, free of charge, to any person obtaining a copy 4 | #of this software and associated documentation files (the "Software"), to deal 5 | #in the Software without restriction, including without limitation the rights 6 | #to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | #copies of the Software, and to permit persons to whom the Software is 8 | #furnished to do so, subject to the following conditions: 9 | # 10 | #The above copyright notice and this permission notice shall be included in 11 | #all copies or substantial portions of the Software. 12 | # 13 | #THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | #IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | #FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | #AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | #LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | #OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | #THE SOFTWARE. 20 | 21 | 22 | if [ -f /etc/lsb-release ]; then 23 | TYPE="UBUNTU" 24 | elif [ -f /etc/debian_version ]; then 25 | TYPE="DEBIAN" 26 | fi 27 | 28 | case ${TYPE} in 29 | "UBUNTU") 30 | VERSION=`grep "DISTRIB_CODENAME" /etc/lsb-release | awk -F = '{ print $2 }'` 31 | ;; 32 | "DEBIAN") 33 | VERSION="Debian `cat /etc/debian_version`" 34 | ;; 35 | esac 36 | 37 | 38 | HOSTNAME=`hostname` 39 | EMAIL="you@yourdomain.com" 40 | SUBJECT="Updates for host ${HOSTNAME}" 41 | DATE=`date +%d.%m.%Y` 42 | AVAIL_UPD=`apt-get -s upgrade | awk '/[0-9]+ upgraded,/ {print $1}'` 43 | 44 | function mailupdates { 45 | 46 | echo -e "--- Updates for host: ${HOSTNAME} ---" 47 | echo -e "Date: ${DATE} \n\n" 48 | 49 | echo -n "Total updates available: " 50 | apt-get -s upgrade | awk '/[0-9]+ upgraded,/ {print $1}' 51 | echo -e "\n\n" 52 | 53 | for i in `aptitude search ~U | cut -c 5- | awk '{ print $1 }'`; do 54 | echo "-- Package: ${i} --" 55 | apt-cache policy ${i} | grep 'Installed\|Candidate' 56 | if [ $TYPE="UBUNTU" ]; then 57 | echo "Package Information: http://packages.ubuntu.com/${VERSION}/${i}" 58 | fi 59 | echo -e "-- End package ${i} --\n" 60 | done 61 | 62 | } 63 | 64 | 65 | if [[ ${AVAIL_UPD} == 0 ]]; then 66 | #echo "No updates available for host $HOSTNAME on date ${DATE}" | mail -s "${SUBJECT}" ${EMAIL} 67 | sleep 1 68 | else 69 | mailupdates | mail -s "${SUBJECT}" ${EMAIL} 70 | fi 71 | --------------------------------------------------------------------------------