Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have a PC running Ubuntu server.

Sometimes when I ssh into it, I get a message that some packages need upgrading.

I upgrade the software by running (as root)

aptitude update && aptitude safe-upgrade

Sometimes that is enough. But sometimes I need to reboot as well, and I am not told this until I ssh in subsequently. How can I find out sooner?

Ideally I'd like to upgrade by running something like

aptitude update && aptitude safe-upgrade &&
if aptitude needs-reboot ; then shutdown -r now ; fi

but the aptitude needs-reboot command does not exist. What should I run instead?


Clarifications:

  • Actually I have two PCs, one running 10.04 (lucid) and the other running 11.04 (natty). I'd hope it would be the same solution for both.
  • Strictly command line solutions only please. One of these PCs doesn't have a display, and neither of them has a keyboard.
share|improve this question
add comment

2 Answers

How about this (run as root): apt-get update && apt-get dist-upgrade --dry-run | grep linux-; if [ $? -eq 0 ]; then yes | apt-get dist-upgrade && reboot; else yes | apt-get dist-upgrade; fi

If there is a kernel update grep linux- will return 0 and then you will reboot. The yes command could be replaced by apt-get dist-upgrade --assume-yes. There will be no reboot if no kernel update is found.

share|improve this answer
add comment

You only need to reboot if the kernel is upgraded.

share|improve this answer
    
Is there an easy way of scripting that, without resorting to parsing the output of aptitude safe-upgrade? –  dave4420 Jul 29 '11 at 17:30
add comment

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.