apt-logger 是一個不到十行的小程式,當管理者使用 apt-get install 安裝或升級軟體時,會自動加註一筆資料到 syslog。如此便可追蹤安裝紀錄。(只有使用 apt-get 安裝會紀錄,手動使用 dpkg -i 無效)
filename: apt-logger
- 代碼: 選擇全部
#!/bin/sh
# apt-logger - apt install logger
# Copyright 2004 Taiwan Debian GNU/Linux Communtiy
# Licensed under the GNU General Public License, version 2. See the file
# /usr/share/common-licenses/GPL or <http://www.gnu.org/copyleft/gpl.txt>.
#
# Install:
# install -d /usr/local/bin
# install --owner=root --group=root --mode=755 \
# apt-logger /usr/local/bin/apt-logger
# cat > /etc/apt/apt.conf.d/90logger <<EOF
# DPkg::Pre-Install-Pkgs {'/usr/local/bin/apt-logger'};
# EOF
# Depends: coreutils, bsdutils
# $Id: $
export LC_ALL=C
while read pkg ; do
package=$(dpkg -f $pkg Package) ;
version=$(dpkg -f $pkg Version);
/usr/bin/logger -t "apt-get" "install $package $version";
done < /dev/stdin
have fun.