a little bash script to check package management history

hakerdefo

This handy script makes it very easy to extract package management details like installation, update, removal, and rollback. Basic usage of script goes like this.
For getting information on packages installed,
apthistory install
For getting information on removed packages,
apthistory remove
To check package upgrades
apthistory upgrade
To list rolledback packages,
apthistory rollback
Ofcourse you can pipe the output and grep to your heart's content  8)
Here's the script,

#!/bin/bash

### Author:      Benjamin York
### Date:        2011-01-08
###
### Based On:
### http://linuxcommando.blogspot.com/2008/08/how-to-show-apt-log-history.html
###
### Hosted At:
### https://github.com/blyork/apt-history
###
### Git Repository:
### git://github.com/blyork/apt-history.git
###
### Description:
### Parses dpkg log files to get package installation, removal, and rollback
### information.
###
### Ubuntu Server likes to split up the dpkg.log file and then compress the
### various pieces. After seeing LinuxCommando's function, I added functionality
### to pull the pieces back together. I also slightly adjusted the output to
### avoid false positives.

function echoHistory(){
    if [[ $1 == *.gz ]] ; then
        gzip -cd $1
    else
        if [[ $1 == *.log || $1 == *.log.1 ]] ; then
            cat $1
        else
            echo "\*\*\* Invalid File: ${1} \*\*\*" 1>&2
        fi
    fi
}

FILES=( `ls -rt /var/log/dpkg.log*` ) || exit 1

for file in "${FILES[@]}"
do
    case "$1" in
        install)
            echoHistory $file | grep " install "
        ;;

        upgrade|remove)
            echoHistory $file | grep " ${1} "
        ;;
                 
        rollback)
            echoHistory $file | grep upgrade | \
                grep "$2" -A10000000 | \
                grep "$3" -B10000000 | \
                awk '{print $4"="$5}'
        ;;

        list)
            echoHistory $file
        ;;

        *)
            echo "Parameters:"
            echo "     install  - Lists all packages that have been installed."
            echo "     upgrade  - Lists all packages that have been upgraded."
            echo "     remove   - Lists all packages that have been removed."
            echo "     rollback - Lists rollback information."
            echo "     list     - Lists all contents of dpkg logs."
            break
        ;;
    esac
done

exit 0

Cheers!!!
You Can't Always Git What You Want

VastOne

Nice!  I lub it

Gonna include it as aliases on VSIDO

Thanks mate!
VSIDO      VSIDO Change Blog    

    I dev VSIDO