Author Topic: a little bash script to check package management history  (Read 3005 times)

hakerdefo

  • Posts: 525
    • View Profile
    • Looking at Linux through the Windows of Life
a little bash script to check package management history
« on: May 11, 2014, 11:35:44 AM »
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,
Code: [Select]
apthistory installFor getting information on removed packages,
Code: [Select]
apthistory removeTo check package upgrades
Code: [Select]
apthistory upgradeTo list rolledback packages,
Code: [Select]
apthistory rollbackOfcourse you can pipe the output and grep to your heart's content  8)
Here's the script,
Code: [Select]
#!/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

  •      v-ger
  • Posts: 4308
    • View Profile
    • VSIDO Community
Re: a little bash script to check package management history
« Reply #1 on: May 11, 2014, 01:56:54 PM »
Nice!  I lub it

Gonna include it as aliases on VSIDO

Thanks mate!
VSIDO      VSIDO Change Blog      I am Terry Ganus on Post     

    I dev VSIDO