0

I have configured unattended-upgrades to run automatically on an Ubuntu Server 18.04. This is working as intended.

How can I check the result of the last unattended-upgrades run through a bash script? In particular, I want to detect if downloading update repository lists or downloading or installing any updated package has failed, for whatever reason. I don't need access to error messages, a single boolean flag whether the unattended upgrade succeeded or failed is sufficient. This information will later be used to indicate whether human interaction is required.

Clarification: I do not want to access the current unattended upgrades status, I want to access the result (success/failure) of the last time unattended upgrades ran.

Cybran
  • 339
  • 3
  • No, this does not answer my question. I want the result, not the current status – Cybran Aug 16 '18 at 12:27
  • 1
    How to tell which step apt is running right now:

    One easy way is to check the logfile.

    $ less /var/log/unattended-upgrades/unattended-upgrades.log

    – abu_bua Aug 16 '18 at 12:38
  • @abu_bua Please re-read the question. I am not interested in current step, I want the result of the entire last run – Cybran Aug 16 '18 at 12:46
  • @user535733 Sorry, but I fail to see how. The only result part I see is the presence of update-success-stamp, which is written by other apt invocations as well (not only u.u.) and only covers successful renewal of the repo lists, not upgraded packages. There is no stamp for the successful completion of u.u. If parsing the log file is an option, the referenced answer does not conclude which conditions must be checked to infer successful or erronous u.u. completion – Cybran Aug 16 '18 at 13:05
  • Doesn't Linux log everything somewhere under /var/log/ ? Check under these files there to see. – Suhaib Aug 18 '18 at 15:58

1 Answers1

4

Apt does not issue a signal, log entry, or timestamp signifying successful upgrade completion without error. The developers assume that successful completion should follow the linux tradition of feedback only upon error.

Instead of using shell scripts to interact with apt, look into using aptdaemon, the tool intended for the purpose.

user535733
  • 62,253
  • Feedback upon error is also very welcome - can you elaborate on how to reliably detect errors? Is it sufficient to parse the unattended upgrade log? – Cybran Aug 16 '18 at 22:45
  • How to reliably detect and parse errors is a completely different question from what you originally asked, so not really appropriate for AskUbuntu's Q/A format. You might interested in http://ubuntuforums.org, our sibling official Ubuntu support site that supports such conversational threads and wandering topics. The apt developers have not, to my knowledge, created a machine-readable output system beyond the aptdaemon API. Logs and output are meant for a human, and may not use easy-to-parse language. – user535733 Aug 17 '18 at 01:08
  • Though it's not what I originally asked, it would be one possible way to solve my original problem. Anyway, thank you for the aptdaemon reference and the information about apt and apt logs! – Cybran Aug 17 '18 at 14:45