Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I'm having trouble creating a cronjob for automatic security updates on my ubuntu server 12.04.

I separated the security sources into a different file, and then did this from within a cronjob:

PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
apt-get -o Dir::Etc::sourcelist="security-sources.list" -o Dir::Etc::sourceparts="-" update -y
apt-get -o Dir::Etc::sourcelist="security-sources.list" -o Dir::Etc::sourceparts="-" upgrade -y

But I'm getting all kind of weird messages in the log:

Example 1:

debconf: unable to initialize frontend: Dialog
debconf: (TERM is not set, so the dialog frontend is not usable.)
debconf: falling back to frontend: Readline
debconf: unable to initialize frontend: Readline
debconf: (This frontend requires a controlling tty.)
debconf: falling back to frontend: Teletype
dpkg-preconfigure: unable to re-open stdin:

Example 2:

Unpacking replacement python-apport ...
Preparing to replace apport 2.0.1-0ubuntu15 (using .../apport_2.0.1-0ubuntu15.1_all.deb) ...
stop: Job failed while stopping
invoke-rc.d: initscript apport, action "stop" failed.

Example 3:

Unpacking replacement dh-apparmor ...
Processing triggers for ureadahead ...
Processing triggers for man-db ...
debconf: unable to initialize frontend: Dialog
debconf: (TERM is not set, so the dialog frontend is not usable.)
debconf: falling back to frontend: Readline
debconf: unable to initialize frontend: Readline
debconf: (This frontend requires a controlling tty.)
debconf: falling back to frontend: Teletype
Processing triggers for shared-mime-info ...

After receiving these logs in my email inbox, I logged in via ssh and saw this:

44 packages can be updated.
24 updates are security updates.

So I guess it didn't work.

Any thoughts?

share|improve this question
3  
Why don't you use unattended-upgrades? It is specifically designed to do just this. –  Gerhard Burger Jan 30 '13 at 10:20
    
@GerhardBurger But that won't let me choose the exact time when it happens. I don't want it to happen in a peak hour. –  ChocoDeveloper Jan 31 '13 at 5:50
1  
Partly true, it will make a job in the cron.daily if I am correct, but you can change when cron.daily runs by editing the /etc/cronjob file, see this question for more information. Apart from that, unattended-upgrades sleeps for a random interval so that not all users update at the same time, because then the servers would be crushed... –  Gerhard Burger Jan 31 '13 at 9:31
    
@GerhardBurger I see, thanks. –  ChocoDeveloper Jan 31 '13 at 9:43
    
I put my comments and some additional information about automatic security updates into an answer. –  Gerhard Burger Jan 31 '13 at 10:17
add comment

1 Answer

up vote 2 down vote accepted

Not really an answer to your scripting problem, but I recommend using the unattended-upgrades Install unattended-upgrades package. It is specifically designed to do just that. You don't have to worry about updating at a peak hour, because unattended-upgrades is run with a random delay (max 30 minutes) because otherwise the servers are being crushed.

If you still want to change the time your updates are done, it is useful to know that the unattended-upgrades is in cron.daily. You can change when cron.daily is executed by editing the /etc/crontab file, for more information see this question.


If you want more information about setting up automatic updates in general (including some pointers on how to write your own cron job) see the Ubuntu help page on AutomaticSecurityUpdates.

share|improve this answer
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.