15

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

Old account
  • 467
  • 3
  • 5
  • 14

3 Answers3

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.

goedson
  • 411
  • 2
  • 5
  • 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 06 '11 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 06 '11 at 21:39
  • The immediate following line isn't always `End-Date:` - sometimes it is `Remove:`. So slightly more complicated to write a script. – Hamish Downer May 18 '12 at 13:15
  • 1
    I've written a nagios plugin based on this idea - https://github.com/aptivate/check_apt_last_update – Hamish Downer Jun 05 '12 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 08 '20 at 15:47
5

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.

thinice
  • 4,676
  • 20
  • 38
  • which log files should I look at (if there are any)? – Old account Jun 06 '11 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 06 '11 at 17:56
2

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.

cstamas
  • 6,607
  • 24
  • 42
  • 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 06 '11 at 21:35