16

I want to know when we last ran the package upgrades/updates on our Debian server.

3 Answers 3

13

The file /var/log/apt/history.log gives you information on when APT was run and what was done.

tail -3 /var/log/apt/history.log

will give you this information for the last run of APT (not necessarily the last run of upgrage, though).

To find out when was the last time you've run an upgrade, you want to look for a line starting with Upgrade: and then lookup up the timestamp in the following line of the file (which starts with End-Date:). The last such match is the last time you've run an upgrade.

6
  • 1
    Well, actually, it does show the commands that were run, including upgrades. However, if the event is a while back, you might have to look at the compressed log files, in which case tail won't work. You would have to unzip the files first.
    – wolfgangsz
    Jun 6, 2011 at 16:23
  • @wolfgangsz You're right. By what I can see in my system, these files are rotated monthly. So, if your last upgrade was more than a month ago (or if you are in the beginning of a month) you might have to look in the previous files.
    – goedson
    Jun 6, 2011 at 21:39
  • The immediate following line isn't always End-Date: - sometimes it is Remove:. So slightly more complicated to write a script. May 18, 2012 at 13:15
  • 1
    I've written a nagios plugin based on this idea - github.com/aptivate/check_apt_last_update Jun 5, 2012 at 12:31
  • Thnx, ended up with grep "apt upg" -n1 /var/log/apt/history.log | head -n1 | xargs | cut -f2-3 -d" " --if they are in archived logs not history.log then it's old as frick so assume not run recently.
    – Tyeth
    Sep 8, 2020 at 15:47
4

Outside of lucking out on log files located in /var/log/apt - e.g.: /var/log/apt/var/log/history.log or /var/log/term.log

The closest thing I can think about is to examine dpkg:

ls -alt /var/lib/dpkg/info | head -n 10

The dates on the top should approximate the last time apt handled those packages.

2
  • which log files should I look at (if there are any)?
    – user18233
    Jun 6, 2011 at 15:22
  • 1
    If you have an abundance of compressed history.x.gz logs you can traverse them using (I wouldn't suggest zcat'ting a large collection of active logs, but this should be fine for these ones) zcat history.log.* |head -n 10
    – thinice
    Jun 6, 2011 at 17:56
1

There are some other comments that are not bad, but what you are really looking for is /var/log/dpkg.log.

dpkg is a low level tool for manipulating packages thus every package modification will be logged there.

1
  • 3
    And, being low level, you can't know if the actions logged by it are the result of an apt-get install xxx or apt-get upgrade or even an dpkg -i xxx.deb. For finding out when you ran package upgrades, it's better to look into APT's logs.
    – goedson
    Jun 6, 2011 at 21:35

You must log in to answer this question.