A collection of Debian Tips

Keeping your apt repository up to date and clean of misc. packages

I have a small script I run from cron each night to clean up the apt database, update from my APT sources, download (but not install) any new packages, and email me the results.

cat << END > /tmp/upgrade-apt
#!/bin/sh
###
SUBJECT="APT update on `hostname` for \`date\`"
MAILTO=mkovach
###
exec 2>&1
(echo "Running autoclean"
/usr/bin/apt-get autoclean -y
echo "Running update"
/usr/bin/apt-get -t sarge-backports update > /dev/null
echo "Running upgrade, but only downloading files"
/usr/bin/apt-get --download-only --yes -t sarge-backports upgrade echo "Done.") \
| mailx -s "\$SUBJECT" \$MAILTO
exit 0
END
  
sudo mv /tmp/update-apt /etc/cron.daily
sudo chmod 755 /etc/cron.daily/upgrade-apt

Large output for dpkg

Running dpkg -l can generates (typically) the following output:

mkovach@kuiper:~$ dpkg -l | head -n 10
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Installed/Config-files/Unpacked/Failed-config/Half-installed
|/ Err?=(none)/Hold/Reinst-required/X=both-problems (Status,Err: uppercase=bad)
||/ Name           Version        Description
+++-==============-==============-============================================
ii  aalib1         1.4p5-22       ascii art library
ii  aalib1-dev     1.4p5-22       ascii art library, development kit
ii  adduser        3.63           Add and remove users and groups
ii  analog         5.32-14        analyzes logfiles from web servers
ii  apache-common  1.3.33-6sarge3 support files for all Apache webservers

Sometimes the name is cut off, this can be confusing and if you are using dpkg -l output in a script, you might not get all the information you need.

mkovach@kuiper:~$ dpkg -l | awk 'BEGIN { print "Kernel Packages installed"} ($1 ~ /^ii/ && $2 ~ /^kernel/) {print $2}' 
Kernel Packages installed
kernel-headers
kernel-headers
kernel-image-2
kernel-kbuild-

You can set a variable COLUMNS and dpkg will use that many columns when displaying the output. Sure this will overrun a 80 column display, but it works nicely for scripting.

mkovach@kuiper:~$ env COLUMNS=132 dpkg -l | head -n 10
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Installed/Config-files/Unpacked/Failed-config/Half-installed
|/ Err?=(none)/Hold/Reinst-required/X=both-problems (Status,Err: uppercase=bad)
||/ Name                        Version                   Description
+++-===========================-===========================-=====================================
ii  aalib1                      1.4p5-22                    ascii art library
ii  aalib1-dev                  1.4p5-22                    ascii art library, development kit
ii  adduser                     3.63                        Add and remove users and groups
ii  analog                      5.32-14                     analyzes logfiles from web servers
ii  apache-common               1.3.33-6sarge3              support files for all Apache webservers

mkovach@kuiper:~$ env COLUMNS=132 dpkg -l | awk 'BEGIN { print "Kernel Packages installed"} ($1 ~ /^ii/ && $2 ~ /^kernel/) {print $2}' 
Kernel Packages installed
kernel-headers-2.6.8-2
kernel-headers-2.6.8-2-686
kernel-image-2.6.8-2-686
kernel-kbuild-2.6-3

Debian_Tips (last edited 2009-11-12 16:36:28 by localhost)