Hello,
last weekend I was helping a friend to check his Ubuntu system. With the command line
crissa@unseen:~$ dpkg --list | grep -v "^ii" | tail -n+6
I found a lot of not complete removed packets. It was a long list, but we didn’t count them. The command “dpkg –list” shows the installed packets and their install status. With “grep -v “^ii”” I filter the correct installed packets and with “tail -n+6” I remove the first 5 lines from the top of the output. (On my Debian system called unseen all packets are correct installed.)
After I removed squid (with “apt-get remove squid” as root) on another system called lostin I got this output:
crissa@lostin:~ ssh$ dpkg --list | grep -v "^ii" | tail -n+6 rc squid 2.4.6-2woody8 Internet Object Cache (WWW proxy cache)
The head of the output of “dpkg –list” shows what is the meaning of the status “rc”:
crissa@lostin:~ ssh$ dpkg --list | head 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 +++-==============-==============-============================================
The package is in the status “remove” and “config-files”. For a package that has no install problems you will find the status “ii”, “install” and “installed”. So far I only saw the status “ii” and the status “rc” on my systems.
I already added the command “dpkg –list | grep -v “^ii” | tail -n+6″ to my crontab, but for my friend I was looking for a better solution:
#!/bin/sh # dpkglist # 20110104 crissa for http://blog.rotten.li dpkg --list | awk ' { if ($1 ~ /^\+\+\+/) { head = 1; next; } if (head) { print $0; } else { next; } } ' | awk ' { sum++; status[$1]++; if ($1 !~ /^ii/) { cnt++; line[cnt]=$0; } } END { print "---------"; for (x in status) { printf "%-3s %4d\n", x, status[x]; } printf "sum %4d\n", sum; print "---------"; for (x=1; x<=cnt; x++) { print line[x]; } if (cnt) print "---------"; } ' # eof
This script doesn’t use temporary files (read Safely Creating Temporary Files in Shell Scripts for more information about the problems with temporary files). The script is checking which lines to skip. It looks for any status and not just “ii” and “rc”. And it counts the lines:
crissa@lostin:~ ssh$ dpkglist --------- rc 1 ii 679 sum 680 --------- rc squid 2.4.6-2woody8 Internet Object Cache (WWW proxy cache) ---------
This script can be started as normal user so I added it to my user crontab:
crissa@unseen:~$ crontab -l # m h dom mon dow command 07 07 * * 0 /usr/local/bin/dpkglist
The script is running every Sunday (the “0” under dow => day of week) at 7 minutes past 7 (the “7” under m => minute and the “7” under h => hour). See cron – Wikipedia, the free encyclopedia for more information.
At last I removed squid with “dpkg –purge squid ; cd /var/cache ; rm -rf squid/” from the system lostin.
After my friend removed all the packets with the status “rc” some problems he had with his Ubuntu system were solved. I had the same experience with one of my systems, after I did some packet uncluttering logrotate was working again.
If you have strange problems on you system a little check with this script wouldn’t harm. But keep in mind that removing the wrong packets could do great harm. So be careful, you have been warned!
Bye, Tore