[Techtalk] querying RPM for recently installed packages

John Clarke johnc+linuxchix at kirriwa.net
Wed May 26 15:27:15 EST 2004


On Tue, May 25, 2004 at 09:05:32PM -0700, Carla Schroder wrote:
> On Tuesday 25 May 2004 5:50 pm, Anthony Gorecki wrote:
> > On May 25, 2004 5:09 pm, Carla Schroder wrote:
> > > But there must be a way to filter the output to select by date...?
> > 
> > An elegantly written pipe to egrep should accomplish what you're looking 
> for.
> 
> Elegant pipe, my eye, I think it will take an entire plumbing system. There 

It's not *that* hard.  Use date +%s -- it prints the date & time as
seconds since the epoch, which is an easy way to convert dates into
numbers that you can compare:

    [johnc at dropbear ~] rpm -q kernel --last
    kernel-2.4.20-30.7.legacy              Wed 17 Mar 2004 12:06:06 PM EST
    [johnc at dropbear ~] date +%s
    1085547940
    [johnc at dropbear ~] date +%s -d "Wed 17 Mar 2004 12:06:06 PM EST"
    1079485566

This script prints all packages installed withing the last n days:

    #/bin/bash

    if [ -z "$1" ]
    then
        echo "Usage: $0 limit(days)"
        exit 1
    fi

    # current time as seconds since the epoch
    now=`date +%s`
    # cutoff time as seconds since the epoch
    limit=$(($now - $1 * 86400))
    # set IFS to newline so that the loop variable contains the
    # package name and date
    IFS='
    '
    # query the rpm database
    for i in `rpm -qa --last`
    do 
        # split the line into package name and date
        package=`echo $i|cut -d ' ' -f 1`
        date=`echo $i|cut -d ' ' -f 2-`
        # convert date into seconds since the epoch
        time=`date +%s -d "$date"`
        if [ $time -lt $limit ]
        then 
            # this package was installed in the last $1 days
            echo $package: $date 
        else
            # no need to examine any more packages since they're printed
            # in time order
            break
        fi
    done
    
e.g.:

    [johnc at dropbear ~/]$ ./rpmquery.sh 45
    smartmontools-5.30-1:                  Fri 23 Apr 2004 12:44:27 PM EST

    [johnc at dropbear ~/]$ ./rpmquery.sh 90
    smartmontools-5.30-1:                  Fri 23 Apr 2004 12:44:27 PM EST
    gcc-g77-2.96-113:                      Fri 19 Mar 2004 10:24:30 AM EST
    kernel-source-2.4.20-30.7.legacy:      Wed 17 Mar 2004 12:07:39 PM EST
    kernel-2.4.20-30.7.legacy:             Wed 17 Mar 2004 12:06:06 PM EST
    kernel-doc-2.4.20-30.7.legacy:         Wed 17 Mar 2004 12:01:21 PM EST
    tcpdump-3.6.3-17.7.3.4.legacy:         Wed 17 Mar 2004 11:59:36 AM EST
    slocate-2.7-1.7.3.legacy:              Wed 17 Mar 2004 11:59:35 AM EST
    screen-3.9.11-4.legacy:                Wed 17 Mar 2004 11:59:33 AM EST
    ethereal-gnome-0.9.16-0.73.2.legacy:   Wed 17 Mar 2004 11:59:31 AM EST
    ethereal-0.9.16-0.73.2.legacy:         Wed 17 Mar 2004 11:59:25 AM EST
    libpcap-0.6.2-17.7.3.4.legacy:         Wed 17 Mar 2004 11:59:13 AM EST
    cvs-1.11.1p1-9.7.legacy:               Wed 17 Mar 2004 11:59:10 AM EST
    arpwatch-2.1a11-17.7.3.4.legacy:       Wed 17 Mar 2004 11:59:06 AM EST


Cheers,

John
-- 
I set a Megahal trained on my own lines, Elvis Costello lyrics, random
Perl and ASR onto IRC as myself yesterday.
Nobody noticed.
                -- Simon Cozens


More information about the Techtalk mailing list