2

I'm installing updates on a bunch of machines, and I simply want to run:

sudo apt-get update
sudo apt-get upgrade
sudo reboot

all at once on all machines (after hours of course) and let them run without requiring my input for passwords. However, the above commands don't work, because they all require root permission, and thus require my password each time. Running them all under a single sudo concatentated by && doesn't seem to work. Also, if an update has release notes, it'll display any release notes and halt until I exit less.

How do I accomplish this?

1
  • 4
    How about sudo sh -c 'apt-get update && apt-get upgrade -y && reboot'?
    – muru
    Jan 7, 2015 at 22:45

3 Answers 3

5

sudo -s will prompt you for your password once, then leave you sitting in a root shell that remains until you exit. There you can chain commands like apt-get update && apt-get upgrade -y && reboot.

3

So you don't want your user to have to type in a password to use sudo? You could add a line like this into /etc/sudoers or a file in /etc/sudoers.d/

    username  ALL=(ALL) NOPASSWD: ALL
    

    Or to just allow a few programs like reboot and apt-get:

    username ALL=(ALL) NOPASSWD: /sbin/reboot, /usr/bin/apt-get
    

Might want to look into some apt-get options too like:

       -q, --quiet
           Quiet; produces output suitable for logging, omitting progress
           indicators. More q's will produce more quiet up to a maximum of 2.
           You can also use -q=# to set the quiet level, overriding the
           configuration file. Note that quiet level 2 implies -y; you should
           never use -qq without a no-action modifier such as -d, --print-uris
           or -s as APT may decide to do something you did not expect.
           Configuration Item: quiet.
    
       -y, --yes, --assume-yes
           Automatic yes to prompts; assume "yes" as answer to all prompts and
           run non-interactively. If an undesirable situation, such as
           changing a held package, trying to install a unauthenticated
           package or removing an essential package occurs then apt-get will
           abort. Configuration Item: APT::Get::Assume-Yes.
    
       --force-yes
           Force yes; this is a dangerous option that will cause apt to
           continue without prompting if it is doing something potentially
           harmful. It should not be used except in very special situations.
           Using force-yes can potentially destroy your system! Configuration
           Item: APT::Get::force-yes.
    

Or you could blindly pipe a few newlines or "q"'s into apt-get, I used to install one package that would ignore apt options like -y and wait for a keypress (probably in it's preinst or postinst script). Could try something like:

    {
    sleep 20
    echo
    echo "q"
    } | apt-get upgrade
    


And if you're installing the exact same packages in every machine, you don't need to update and upgrade each one over the internet, you can download all the required .deb files once with:

    sudo apt-get install --download-only [packages]
    

    or

    sudo apt-get upgrade --download-only
    

then install them all from a local / shared folder with

    sudo dpkg -iR /folder_of_debs
    

2
  • I don't think the line you suggest adding to the sudoers file should be used. The user could easily break his system, as entering a password makes you think about whether it's good to run this command. However, I use this line to remove password entering from shutdown, poweroff and reboot: username ALL=(ALL) NOPASSWD: /sbin/poweroff, /sbin/reboot, /sbin/shutdown, as I often run this commands, and here the password annoys me.
    – s3lph
    Jan 7, 2015 at 23:48
  • @the_Seppi That's a good idea, all depends if the user is a regular user, or a "setup only" admin-type user that would want to never want a sudo password. I'll add in a line with just those & apt-get too, thanks
    – Xen2050
    Jan 7, 2015 at 23:54
0

The really simplest solution if you're 'root' is

apt-get -y update && apt-get -y upgrade && reboot

And if you're a user on the system, firstly make sure the user is enabled in the sudoers then type:

sudo apt-get -y update && apt-get -y upgrade && reboot

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .