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?
Not really an answer to your scripting problem, but I recommend using the 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 incron.daily
. You can change whencron.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.