Last active
August 13, 2020 12:16
-
-
Save dpanter/49f04fc4dafcaa3be8f1725382aceb05 to your computer and use it in GitHub Desktop.
aptwhen.sh - Easily check dpkg logs for when a package was installed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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