SEARCH

Enter your search query in the box above ^, or use the forum search tool.

You are not logged in.

#1 2012-11-26 03:53:44

rkwurth
#! Junkie
Registered: 2012-09-04
Posts: 365

Script to show recently installed packages

This script show which packages were installed, removed, and installed but not removed in a day. You can use it to calm that uneasy feel after a botched source code compilation during which you had to grab just a few dependencies, then just a few more, ect.

Usage example: packagecheck.sh 2012-11-25

To run the script w/o any modifications, just place it in ~/bin, chmod +x ~/bin/packagecheck.sh, and mkdir ~/bin/packagecheck.

#!/bin/bash

# Show recently installed packages

DATE="$1"
DIR=/home/$USER/bin/packagecheck

cat /var/log/dpkg.log* | grep $DATE | grep "\ install\ " | awk ' { print $4" "substr($0,length($0)-8) }' | egrep -o '^[^:]+' | sort > $DIR/installed

cat /var/log/dpkg.log* | grep $DATE | grep "\ remove\ " | awk ' { print $4" "substr($0,length($0)-8) }' | egrep -o '^[^:]+' |  sort > $DIR/removed

KEPT=`comm -23 $DIR/installed $DIR/removed`

printf "INSTALLED PACKAGES:\n`cat $DIR/installed`\n" 

printf "REMOVED PACKAGES:\n`cat $DIR/removed`\n"

printf "PACKAGES INSTALLED BUT NOT REMOVED:\n$KEPT\n"

Any comments or critiques are welcome.

Last edited by rkwurth (2012-11-26 04:10:17)

Offline

Help fund CrunchBang, donate to the project!

#2 2012-11-26 05:00:47

mitchejj
Member
Registered: 2012-11-24
Posts: 11

Re: Script to show recently installed packages

I'm really rusty when it comes to scripting, its been years. With that said might  I suggest:

if [ ! -d $DIR ]; then
	mkdir $DIR
fi

This would then eliminate the need for the end user to create the sort directory. I would also think it might be wise to move the sorting directory out a users $PATH.

See gist: 4146675

Last edited by mitchejj (2012-11-26 05:13:27)

Offline

#3 2012-11-26 05:16:17

rkwurth
#! Junkie
Registered: 2012-09-04
Posts: 365

Re: Script to show recently installed packages

Sure, that'd be fine.

Last edited by rkwurth (2012-11-26 11:09:16)

Offline

#4 2012-12-22 16:36:39

rkwurth
#! Junkie
Registered: 2012-09-04
Posts: 365

Re: Script to show recently installed packages

Still having fun with this thing. After looking around online, I see similar scripts, most commonly one-liners that grep " install " from dpkg.log. I'm hoping to implement a few more options- any ideas?

pkgcheck.sh
just chmod +x and run pkgcheck.sh [-i][-r][-c] YYYY-MM-DD

#!/bin/bash

DATE=$2
LOG=/var/log/dpkg.log

checkstat() {
        grep $DATE $LOG | grep $TYPE
}

formatsimple() {
        awk -F '[: ]' '{print $6}' 
}

simplecheckstatinstalled() {
        TYPE="[[:space:]]install[[:space:]]"
        checkstat | formatsimple
}

simplecheckstatremoved() {
        TYPE="[[:space:]]remove[[:space:]]"
        checkstat | formatsimple
}
case $1 in  
        -i) 
        simplecheckstatinstalled
        ;;  
        -r) 
        simplecheckstatremoved
        ;;  
        -c) # Installed but not removed
        comm -23 <(simplecheckstatinstalled | sort) <(simplecheckstatremoved | sort)
        ;;  
        *)  
        echo "pkgcheck.sh [-i][-r][-c] YYYY-MM-DD"
        ;;  
esac

Offline

Board footer

Powered by FluxBB

Copyright © 2012 CrunchBang Linux.
Proudly powered by Debian. Hosted by Linode.
Debian is a registered trademark of Software in the Public Interest, Inc.

Debian Logo