I wrote this bash script to automatically check for updates in the repositories.
Notes:
1. It can be used from the console or set to run periodically as a cronjob (I have it running every 6 hours)
2. It does not perform any upgrades, just reports available updates, so it's 'safe' to use unattended.
3. The reason it uses logs as well as standard output is because I wanted to make it possible to easily monitor updates with apps like SuperKaramba. (you can easily 'grep' the logs in your Karamba themes for the information you need).
Any questions comments and/or improvement suggestions are welcome.
Notes:
1. It can be used from the console or set to run periodically as a cronjob (I have it running every 6 hours)
2. It does not perform any upgrades, just reports available updates, so it's 'safe' to use unattended.
3. The reason it uses logs as well as standard output is because I wanted to make it possible to easily monitor updates with apps like SuperKaramba. (you can easily 'grep' the logs in your Karamba themes for the information you need).
Any questions comments and/or improvement suggestions are welcome.
Code:
#!/bin/bash # Function: Script checks for available updates in sources.log repositories # Output: Screen and two logfiles # Usage: 1. From the console with sudo # 2. Automatic as a cronjob, logs can be monitored with SuperKaramba, for example #Check if root ROOT_UID=0 if [ "$UID" -ne "$ROOT_UID" ] then echo "You need root priviledges to run this script." exit 67 fi #Check repositories and print log to file with possible error messages echo "Updating package lists..." apt-get -ds update > /var/log/repo_get.log 2>&1 # Error check to see if package lists were succesfully loaded (and that apt is not locked by other package managers like synaptic) ERRORS=`grep -c 'E:' /var/log/repo_get.log` if [ "$ERRORS" == 0 ] then grep -i ')' /var/log/repo_get.log echo else grep 'E:' /var/log/repo_get.log echo "Errors while fetching updates...exiting program" exit 1 #Exit on errors to avoid writing an empty update list fi #Writing and sorting available updates apt-get -yus upgrade > /var/log/repo_update.log grep 'Conf ' /var/log/repo_update.log | cut -d ' ' -f2 | sort echo -e '\033[1;32m' grep -i ',' /var/log/repo_update.log | cut -d ',' -f1 echo -e '\033[0m' echo "Done...exiting program" exit 0
Comment