Sunday, April 28, 2024
33
rated 0 times [  33] [ 0]  / answers: 1 / hits: 23571  / 2 Years ago, thu, june 23, 2022, 12:39:49

I'm working on some system admin automation using fabric and I'd like to be able to monitor the number of packages that need upgrading on a given machine. This is the same information that I can see when I first log in to a machine, i.e. this part:



35 packages can be updated.
22 updates are security updates.


Is there a command that I can run (preferably without sudo) that gives just that information?



I've looked at the apt-python bindings, but they seem to have a high learning curve and they also appear to be changed around a lot -- I'd like something that will work at least as far back as lucid without needing to do different things on different Ubuntu versions.


More From » command-line

 Answers
1

To obtain that output, you can use the command



sudo /usr/lib/update-notifier/update-motd-updates-available


or, if you don't want to use sudo,



cat /var/lib/update-notifier/updates-available


Explanation



The login application shows the output found in the file /etc/motd, that is a symbolic link to /var/run/motd.



This last file is updated by the mounted-varrun service (see /etc/init/mounted-varrun.conf) invoking all scripts in /etc/update-motd.d/, and in particular



/etc/update-motd.d/90-updates-available


that in turn calls the script



/usr/lib/update-notifier/update-motd-updates-available


this script executes various actions, and at last writes the output to the text file



/var/lib/update-notifier/updates-available


EDIT



Regarding the reboot part of the question, run this command



/usr/lib/update-notifier/update-motd-reboot-required


it will give no output if reboot is not required.


[#44515] Friday, June 24, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ithriv

Total Points: 46
Total Questions: 115
Total Answers: 96

Location: Malaysia
Member since Wed, May 11, 2022
2 Years ago
;