10

I have a set of custom commands I run on my computers after I install them. How do I make Ubuntu check for updates every 4 weeks and install them automatically on check?

I would need this done via command line so I can set it up for usual users when I set up their computers.

The first command will make the update manager check for updates every 2 weeks because they not always come so much and to save the bandwidth of the Ubuntu servers.

I also need to set it so that users don't need to click to install updates since it's tiring every time I help a friend set up a computer.

0

4 Answers 4

10

First, enable automatic updates like this:

sudo apt-get install unattended-upgrades

You then need to edit its configuration, type

sudo nano /etc/apt/apt.conf.d/50unattended-upgrades

(replace nano with your preferred text editor if you want)

The file looks like this:

Unattended-Upgrade::Allowed-Origins {
        "Ubuntu maverick-security";
//      "Ubuntu maverick-updates";
};

The // means this line is a comment and won't be considered by the program, remove the strokes to include stable release updates in addition to security fixes. Also, replace maverick with the version of Ubuntu you're running.

To set the interval at which the system checks for updates, edit the /etc/apt/apt.conf.d/10periodic file with a text editor:

APT::Periodic::Update-Package-Lists "14";
APT::Periodic::Download-Upgradeable-Packages "14";
APT::Periodic::AutocleanInterval "14";
APT::Periodic::Unattended-Upgrade "14";

In this example, the system is updated every two weeks.

For a more detailed explanation, see Automatic Updates in the Ubuntu server guide.


Note that papukaija's answer is talking about the interval at which the Update Manager dialogue pops up on your screen, I'm guessing that's not what you wan't, but I'm not sure. :)

6
  • Dialogs not needed to pop up and it not going in 1 line. If i set in Software sources 2 weeks to be checked then is it possible that update dialog pops up earlier or later? Needed is that with 1 line would be possible to set up that user wouldnt even know he has system beeing updated every 4 weeks and he doesnt needs to see any updates asking and automatically its just installed. So i dont need to set that manually with mouse in Software sources.
    – Kangarooo
    Jan 26, 2011 at 0:48
  • I'm not sure I understand you. You can disable the update notifications by going to System → Preferences → Startup Applications and removing the check mark at "Update Notifier". Is that what you meant? Also, of course you can set it to "30" instead of "14" days (or any amount you want) Jan 26, 2011 at 1:01
  • And that can be also done with one line? If yes thats also good to do if not- its not main thing i wanted. Main thing is to overcome going to Software sources setings to change update checking and what to do. I want to put check every 28 days and install updates without asking anything in terminal so its faster.
    – Kangarooo
    Jan 26, 2011 at 5:08
  • One line command in my answer: apt-get update && apt-get upgrade -y
    – luri
    Jan 27, 2011 at 23:03
  • @luri that's not what this question is about Jan 27, 2011 at 23:07
2

If you mean update everything "updatable", i.e., update ALL your packages, I guess you could cron (within the root cron) than every 28 days apt-get update && apt-get upgrade -y is run.

Some people have problems with crond jobs because of a restrictive PATH setting. Should you have any problem you can define your PATH at the very beginning of the crontab -e file (as suggested in CronHowto)

Also, to check that everything is going OK, I'd log the results, like this:

root@PORTATIL:/var/log$ crontab -l
* * */2 * * /usr/share/myupdate.sh > /var/log/myupdate.log

myupdate.sh could be as simple as this:

#!/bin/bash
#Testing updates
echo "$(date) Crond myupdate sarting."
apt-get update -y
apt-get upgrade -y
echo "$(date)Crond myupdate finished."
7
  • This doesn't work for me. When I get my cron logs, aptitude -y safe-upgrade is complaining about needing a controlling tty, and then a bunch of path errors. Maybe I should make a question..
    – djeikyb
    Jan 28, 2011 at 21:45
  • Did you set it within the root cron?
    – luri
    Jan 28, 2011 at 21:57
  • Yep. It was failing because of some different path problems, so I made a script at /root/bin, with #!/bin/bash, and full path to apt-get. It works better, but it still doesn't upgrade.
    – djeikyb
    Jan 28, 2011 at 22:48
  • Post the errors in the log.... or whatever fails
    – luri
    Jan 28, 2011 at 23:37
  • I made a separate question: askubuntu.com/q/23795/8515
    – djeikyb
    Jan 29, 2011 at 0:39
1

You can change the interval between the time when update-manager is run by opening gconf-editor (for example with Alt+F2 and typing gconf-editor). Then locate /apps/update-notifier.

The interval is defined in key regular_auto_launch_interval where the value is number of days. I think that this method doesn't affect the non-graphical automatic updater (unattended-upgrades).

Please note that Ubuntu may not automatically install security updates due to a bug.

2
  • 4
    This is the command line version of this answer: gconftool -s /apps/update-notifier/regular_auto_launch_interval --type int 7 (where 7 is the interval in days) Jan 25, 2011 at 1:19
  • I just checked it was already 7. But in Software sources its set 2 weeks. Maybe its somewhere else?
    – Kangarooo
    Jan 26, 2011 at 0:43
0

I put gconftool -s /apps/update-notifier/regular_auto_launch_interval --type int 1 and its opening every day showing i have not installed updates. Does it open if theres no new updates? So then making auto update every 4 weeks would not make this pop up? So then just how to make with CLI to auto install updates every checking every 4 weeks? THats what i want. By not going to Software sources and doing it with mouse. And doing so its possible couse it cant be put more then 2 weeks in there.

You must log in to answer this question.

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