Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I need to find the last time that the

apt-get update

command was run on my server. How can I determine this information?

share|improve this question

9 Answers 9

An "apt-get update" may not create or update files, it does update the cache directory so we can use that to get the timestamp when the last "apt-get update" was run :

stat -c %Y /var/cache/apt/

share|improve this answer
    
Great answer, thanks! –  yanhan Aug 1 at 3:33

At least in Ubuntu systems there is a file /etc/apt/apt.conf.d/15update-stamp containing:

APT::Update::Post-Invoke-Success {"touch /var/lib/apt/periodic/update-success-stamp 2>/dev/null || true";};

So see if you have /var/lib/apt/periodic/update-success-stamp and if you have it, you can use

stat -c %y /var/lib/apt/periodic/update-success-stamp

command to get the the time of the last "apt-get update" invocation.

And if your system does not have that apt configuration file, you can always add it.

share|improve this answer

Synaptic logs a history file (>File > History) , aptitude logs both history in /var/log/aptitude and auto-installed packages in /var/lib/aptitude/pkgstates, so you could check these for latest activity.

share|improve this answer

Don't go from the lock files. Lock files aren't reliable, they tend to move around over time with new Linux releases, and many programs cleanup (remove) lock files when they're done with them.

The following command will get you what you're looking for.

ls -lt --time-style="long-iso" /var/log/apt | grep -o '\([0-9]\{2,4\}[- ]\)\{3\}[0-9]\{2\}:[0-9]\{2\}' -m 1

This is two commands in one. The results of the first command filter into the second through the pipe (|) symbol.

In the first command, I'm using "ls" to list the file contents of the /var/log/apt directory, which is the directory that stores the access history logs for apt-get. The "-lt" part is actually two switches. The first "l" switch tells "ls" to list one file per line with detail. The second "t" switch tells "ls" to sort by date and time. "--time-style" forces the date time to display in the format "YYYY-MM-DD HH:MM".

In the "grep" portion of the command, the "-o" switch tells grep to only show the portions of each line that match the regular expression exactly. The regular expression I've used here detects date times that are in the format specified in the "ls" command. You'll also notice the true little piece of magic on the very end of the "grep" command that there's a "-m" switch with the number "1" immediately following. This tells "grep" to stop looking for matches after it finds the first one.

So, in summary, we're listing the apt log file details so we can see the last modified date, we then sort by date and tell grep to pull the first date off the top, which it then returns. That's the last date that apt-get ran.

To play devil's advocate for a moment, however, it's common for Debian platforms like Ubuntu to schedule apt-get as a job that runs regularly. If you're looking for the person at the other end of the apt-get execution, you may actually find a machine. You could always match up access logs with the apt logs to see if any time stamps coincide. It's also possible to look at a user's command history to an extent.

Hope this helps!

share|improve this answer
1  
Unfortunately not working. In /var/log/apt it is also logged when I for example do an apt-get install some-package. Actually on Ubuntu it does not log something when I do apt-get update –  Alex Oct 20 '12 at 22:19
$ ls -l /var/lib/dpkg/lock 
-rw-r----- 1 root root 0 2011-11-16 09:40 /var/lib/dpkg/lock
share|improve this answer

wrap apt-get in a script that first writes a timestamp to a file, and then does the usual work. that way, you can define the timestamp format and location ;)

share|improve this answer
    
Sujoy, Wrapping it in a script is not practical if you have hundreds of servers, and you do not wish to maintain yet another script that might cause problems the next time you update your apt-get package. I think the requestor is looking for an answer that makes use of information already existing in his computer. –  pdwalker Jan 11 '11 at 14:44

I suspect you can check the last modified times on files /var/cache/apt to figure out when the last updates were applied to the package lists.

I just tested this, and ran "sudo apt-get update" twice in a row, and the dates did not change from their current value, but I suspect this is because there were no new updates to apply, and that the caches are up to date.

share|improve this answer

/var/log/dpkg.log will keep a history of what was done, but not necessarily which app called dpkg (synaptic, apt-get, etc).

share|improve this answer

You could check the Access times on the files in /var/lib/apt/lists which is updated when you run apt-get update. If apt-get update was run with sudo you should have a line logged in /var/log/auth.log when it was done..

share|improve this answer
1  
As pointed out somewhere else, you may find some files aren't updated and therefore haven't been downloaded again. This is fine if you want to know how up to date your package lists are, but not if you want to know when apt-get update was last run. The former is more likely. –  David Pashley Jun 6 '09 at 5:27

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.