Skip to content

Instantly share code, notes, and snippets.

@dpanter

dpanter/aptwhen.sh

Last active Aug 13, 2020
Embed
What would you like to do?
aptwhen.sh - Easily check dpkg logs for when a package was installed
#!/bin/bash
# aptwhen.sh
# Easily check dpkg logs when a package was installed
# Created 2020-04-11 - Updated 2020-08-13
# Written for Siduction (Debian sid based distro)
# By dpanter https://gist.github.com/dpanter
# If no options given, print this message and quit
if [ -z "$1" ]; then
echo "Easily check dpkg logs when a package was installed"
echo "Usage: `basename $0` <package> <option>"
echo "Options can be any APT verb, e.g. install, remove, upgrade etc."
exit 1
fi
# Define log files location
# use /bin/ls to avoid system aliases,single column, natural sort
LOGS=$(/bin/ls -1v /var/log/dpkg.log*)
# zgrep works on uncompressed files as well
# sort numerically in reverse order (newest on top)
for f in $LOGS; do
if [ -z "$2" ]; then
zgrep -e "$1" "$f" | sort -nr
else
zgrep -e "$1" "$f" | grep -e "$2" | sort -nr
fi
done
# Log files usually exist in /var/log/
# dpkg.log
# dpkg.log.1
# dpkg.log.2.gz
# dpkg.log.3.gz
# dpkg.log.4.gz
# dpkg.log.5.gz
# dpkg.log.6.gz
# dpkg.log.7.gz
# dpkg.log.8.gz
# dpkg.log.9.gz
# dpkg.log.10.gz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.