Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have about 7 Debian servers I manage, and I would like to set them to automatically update themselves. So, I created a script as such:

#!/bin/sh
apt-get update
apt-get upgrade

and placed it on the root's crontab list. Unfortunately, it always hangs on the Upgrade section, asking if I'm sure I want to upgrade. Because it's a cron job, I don't see the output until it emails me saying it's failed. Is there a way to have it skip that prompt, and just do the upgrade automatically?

share|improve this question
2  
... or cron-apt. –  derobert Dec 30 '13 at 20:02

3 Answers 3

up vote 12 down vote accepted

Use the -y option to apt-get to have it not ask. From man apt-get:

   -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.

You can also set the DEBIAN_FRONTEND env variable

DEBIAN_FRONTEND=noninteractive apt-get -y upgrade
share|improve this answer
    
What does DEBIAN_FRONTEND do? Is it used for other processes as well? –  Canadian Luke Dec 30 '13 at 19:58
    
I'm trying this on my home server, and will choose the best answer as soon as it runs –  Canadian Luke Dec 30 '13 at 20:04
    
@CanadianLuke see here for DEBIAN_FRONTEND. It's not mentioned in my Debian's man debconf though, so it may be an Ubuntu thing. –  terdon Dec 30 '13 at 20:31
    
@terdon you don't have the -doc package for debconf. It's in the 7 section of the man man 7 debconf ;) –  Braiam Dec 30 '13 at 20:48
    
@Braiam ah, OK, I saw that and tried man 7 debconf but got nothing. Now I know why :) –  terdon Dec 30 '13 at 20:51

Well, maybe you are using the wrong tool. unattended-upgrades package installs security upgrades in daily basis (can be configured), you can configure what packages to upgrade or not upgrade, etc. Can be installed using:

sudo apt-get install unattended-upgrades

From man unattended-upgrades:

The configuration is done via the apt configuration mechanism. The default configuration file can be found at /etc/apt/apt.conf.d/50unattended-upgrades

share|improve this answer
    
@CanadianLuke it reads all the configurations in /etc/apt/apt.conf.d/ but only those starting with Unattended-Upgrade:: get parsed. –  Braiam Dec 30 '13 at 20:04
    
I am trying this on one of the servers at work, and will choose the best answer as soon as it runs –  Canadian Luke Dec 30 '13 at 20:05

A generic tool for this kind of thing is yes:

DESCRIPTION
       Repeatedly output a line with all specified STRING(s), or 'y'.

So, for example, you could do

yes | sudo apt-get upgrade 

Please note that in the specific case of apt-get upgrade using the options suggested by @Braiam or @ArthurUlfeldt is better.

share|improve this answer
    
The line I paste when I want to do it manually is apt-get update && yes | apt-get upgrade (our servers aren't supposed to use sudo... Don't ask...) –  Canadian Luke Aug 14 at 18:54

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.