特殊:Badtitle/NS100:AutoWeeklyUpdateHowTo:修订间差异
小无编辑摘要 |
小无编辑摘要 |
||
(未显示同一用户的5个中间版本) | |||
第2行: | 第2行: | ||
{{Languages|UbuntuHelp:AutoWeeklyUpdateHowTo}} | {{Languages|UbuntuHelp:AutoWeeklyUpdateHowTo}} | ||
== Automatic Package Updates Using cron-apt == | == Automatic Package Updates Using cron-apt == | ||
The package cron-apt is designed to automatically update the package list and download upgraded packages. Therefore it basically calls the | === Desktop method - default === | ||
If you have installed the full desktop version of Ubuntu, everything you need is already installed and running. Package updates can be scheduled from the desktop. | |||
You can change how and when the system updates itself. Click '''System''', '''Administration''', '''Software Sources'''. You will be prompted for your password. Once you've entered that, click '''Updates'''. You'll see various categories of updates, and underneath '''Automatic Updates''', you'll see '''Check for updates:''' and a schedule. You can select daily, weekly, manually etc. You can also select whether you wish the system to: | |||
* Install security updates without confirmation (ie. download '''and''' install) | |||
* Download all updates in the background (ie. download but wait for you to manually install them) | |||
* Only notify about available updates (ie. nag you to manually download updates and to manually install them) | |||
The default is to check daily and notify you. A down-arrow will appear in the desktop notification tray when updates are available, accompanied by a pop-up bubble telling you that updates are available. When it appears, click it, and it will guide you through the update process. | |||
That's it, all done. You do not need to install cron-apt yourself and you can stop reading this page now, safe in the knowledge that your system is receiving the latest security updates and fixes. Of course, it never hurts to learn... | |||
=== cron-apt method === | |||
This method is for people who have installed a cut-down, customised or server version of Ubuntu. If you have installed the full desktop version of Ubuntu, updates are automatically handled by the GUI method described above. There is no need to install cron-apt yourself if you are running the full desktop version of Ubuntu. But the whole point of Linux and open source software is that you ''can'' customise it, right? | |||
The package cron-apt is designed to automatically update the package list and download upgraded packages. Therefore it basically calls the command | |||
<pre><nowiki> | <pre><nowiki> | ||
apt-get update | apt-get update | ||
</nowiki></pre> | </nowiki></pre> | ||
=== Installing Cron-apt === | |||
You can get cron-apt from the Universe Repositories using Synaptic, or from the command line: | |||
<pre><nowiki> | <pre><nowiki> | ||
apt-get | sudo apt-get install cron-apt | ||
</nowiki></pre>. | </nowiki></pre> | ||
=== | By default, cron-apt will execute automatically at 4am. | ||
You can | If your system is normally turned off at 4am, you can either edit '''/etc/cron.d/cron-apt''' and change the schedule to a time when your PC ''is'' likely to be switched on, or you can use Anacron to make it run when your PC is next turned on. | ||
=== | === Making cron-apt execute regularly with Anacron === | ||
To make cron-apt be executed | [[UbuntuHelp:Anacron|Anacron]] makes sure that all the tasks listed in '''/etc/cron.hourly''' , '''/etc/cron.daily''' , '''/etc/cron.weekly''' and '''/etc/cron.monthly''' are performed, even if the PC is switched off when they'd normally happen. Overdue tasks are run when the computer is next turned on. On the good side, it never misses a task. On the bad side, if the tasks take a lot of time, your PC might seem a little slow when you first turn it on after a long time being turned off. | ||
==== Optional: Comment out cron-apt ==== | |||
Anacron does not look in '''/etc/cron.d''' . You may wish to comment out the line in '''/etc/cron.d/cron-apt''' which would otherwise cause it to run at 4am. It won't do any harm to leave it there (you can run cron-apt many times a day without problems), but why would you need to run it both in cron.d and cron.daily or cron.weekly? For the sake of tidyness you can prefix the line: | |||
<pre><nowiki> | |||
0 4 * * * root test -x /usr/sbin/cron-apt && /usr-sbin/cron-apt | |||
</nowiki></pre> | |||
...with a # , which will prevent it from executing at 4am: | |||
<pre><nowiki>{ | |||
# 0 4 * * * root test -x /usr/sbin/cron-apt && /usr-sbin/cron-apt | |||
</nowiki></pre>} | |||
==== Add cron-apt to cron.daily ==== | |||
To make cron-apt be executed by Anacron, create a link in '''/etc/cron.daily''' or '''/etc/cron.weekly'''. For example: | |||
<pre><nowiki> | <pre><nowiki> | ||
sudo ln -s /usr/sbin/cron-apt /etc/cron. | sudo ln -s /usr/sbin/cron-apt /etc/cron.weekly/ | ||
</nowiki></pre> | </nowiki></pre> | ||
Cron-apt only downloads new packages, | ==== Manually apply the updates ==== | ||
Cron-apt only downloads new packages. If you are a desktop user, you will be notified that there are updates waiting by a down-arrow icon in the notification area (it will not appear until there are updates ready). Click this and it will prompt you through the update process. | |||
Alternatively, from the command line you can do: | |||
<pre><nowiki> | <pre><nowiki> | ||
sudo apt-get dist-upgrade | sudo apt-get dist-upgrade | ||
</nowiki></pre> | </nowiki></pre> | ||
== Advanced Alternatives == | |||
== Automatic Weekly Package Updates Using Cron And Apt-Get == | Below are '''alternatives''' to using cron-apt, for '''advanced users only'''. You should use them ''instead'' of cron-apt, but there is '''no point''' doing them in addition cron-apt. You can remove cron-apt with: | ||
<pre><nowiki> | |||
sudo apt-get remove cron-apt | |||
</nowiki></pre> | |||
=== Advanced Alternative: Automatic Weekly Package Updates Using Cron And Apt-Get === | |||
'''WARNING:''' As with any system changes, the potential for creating new or additional problems may occur. | '''WARNING:''' As with any system changes, the potential for creating new or additional problems may occur. | ||
Please be sure to backup your data and configurations! Use this document at your own risk. | Please be sure to backup your data and configurations! Use this document at your own risk. | ||
第28行: | 第57行: | ||
=== Creating the Weekly Cron Job File === | === Creating the Weekly Cron Job File === | ||
First you will need to create the cron job file. You can use a simple text editor to create the file and save it in your home directory. In Ubuntu, open Applications > Accessories > Text Editor. In the Text Editor, type the following lines: | First you will need to create the cron job file. You can use a simple text editor to create the file and save it in your home directory. In Ubuntu, open Applications > Accessories > Text Editor. In the Text Editor, type the following lines: | ||
<pre><nowiki> #!/bin/bash | <pre><nowiki> | ||
#!/bin/bash | |||
apt-get update | apt-get update | ||
apt-get upgrade -y | apt-get upgrade -y | ||
第35行: | 第65行: | ||
=== Moving the Cron Job File to Cron.Weekly === | === Moving the Cron Job File to Cron.Weekly === | ||
Now that you have created the cron job file, it needs to be moved into the weekly cron directory so that it will be run automatically on a weekly basis. To do this, we first need to open a command line terminal. In Ubuntu, click Applications > System Tools > Terminal. Now you should see your terminal prompt. At the prompt type "ls" and press Enter (or Return on some keyboards). In the list you should see your newly created file "autoupdt". | Now that you have created the cron job file, it needs to be moved into the weekly cron directory so that it will be run automatically on a weekly basis. To do this, we first need to open a command line terminal. In Ubuntu, click Applications > System Tools > Terminal. Now you should see your terminal prompt. At the prompt type "ls" and press Enter (or Return on some keyboards). In the list you should see your newly created file "autoupdt". | ||
<pre><nowiki>user@system:~$cd ~ | <pre><nowiki> | ||
user@system:~$cd ~ | |||
user@system:~$ls</nowiki></pre> | user@system:~$ls</nowiki></pre> | ||
Now that we know the file is there, we need to move the file to the proper directory. Type the following command at the command line promt to move the file: | Now that we know the file is there, we need to move the file to the proper directory. Type the following command at the command line promt to move the file: | ||
<pre><nowiki>user@system:~$sudo mv autoupdt /etc/cron.weekly | <pre><nowiki> | ||
user@system:~$sudo mv autoupdt /etc/cron.weekly | |||
</nowiki></pre> | </nowiki></pre> | ||
(You may be prompted to enter your sudo password, which is YOUR password.) Now we need to move to the Cron directory to verify the file was moved. At the command line prompt type: | (You may be prompted to enter your sudo password, which is YOUR password.) Now we need to move to the Cron directory to verify the file was moved. At the command line prompt type: | ||
<pre><nowiki>user@system:~$cd /etc/cron.weekly | <pre><nowiki> | ||
user@system:~$cd /etc/cron.weekly | |||
user@system:~$ls</nowiki></pre> | user@system:~$ls</nowiki></pre> | ||
You should see the "autoupdt" file in the list. (If not, try the previous move command again.) | You should see the "autoupdt" file in the list. (If not, try the previous move command again.) | ||
=== Making the Cron Job File Executable === | === Making the Cron Job File Executable === | ||
Now that the file is created and ready to be run weekly by cron, we still need to make the file executable in order for cron to be able to run it. Since you are already in the cron.weekly directory, all you need to do is enter this command at the prompt: | Now that the file is created and ready to be run weekly by cron, we still need to make the file executable in order for cron to be able to run it. Since you are already in the cron.weekly directory, all you need to do is enter this command at the prompt: | ||
<pre><nowiki>user@system:~$sudo chmod 755 autoupdt | <pre><nowiki> | ||
user@system:~$sudo chmod 755 autoupdt | |||
</nowiki></pre> | </nowiki></pre> | ||
(Again you may be prompted for your sudo password.) | (Again you may be prompted for your sudo password.) | ||
=== Finished === | === Finished === | ||
Now that the file is executable, you are finished. The cron job will run weekly and update your source list (to see if there are any new package updates), update your packages as found and needed, then clean out any old unused no longer installed packages. You can still update using Synaptic Package Manager or apt-get at the command line, but now you can relax a bit knowing your system will be updated automatically on a weekly basis. | Now that the file is executable, you are finished. The cron job will run weekly and update your source list (to see if there are any new package updates), update your packages as found and needed, then clean out any old unused no longer installed packages. You can still update using Synaptic Package Manager or apt-get at the command line, but now you can relax a bit knowing your system will be updated automatically on a weekly basis. | ||
=== | === Advanced Alternative: Package Updates with Logging using Aptitude === | ||
Apt-get doesn't write details of changes it makes to log files. Aptitude logs to /var/log/aptitude, and can mail a report to root, which can be redirected to the sudo user if Postfix is set up to do this. As with the examples above, create this script as /etc/cron.weekly/autoupdt and make it executable: | Apt-get doesn't write details of changes it makes to log files. Aptitude logs to /var/log/aptitude, and can mail a report to root, which can be redirected to the sudo user if Postfix is set up to do this. As with the examples above, create this script as /etc/cron.weekly/autoupdt and make it executable. We use here a special action of aptitude called 'full-upgrade' (which will always upgrade your packages to the latest version, before Ubuntu 7.10 it was called 'dist-upgrade'). However, you might want to have a more conservative action when doing this on a server, the action 'safe-upgrade' is there for you. You can check the guide on aptitude for more information: [[UbuntuHelp:AptitudeSurvivalGuide|AptitudeSurvivalGuide]]. | ||
<pre><nowiki>#!/bin/bash | <pre><nowiki> | ||
#!/bin/bash | |||
tmpfile=$(mktemp) | tmpfile=$(mktemp) | ||
echo "aptitude update" >> ${tmpfile} | echo "aptitude update" >> ${tmpfile} | ||
aptitude update >> ${tmpfile} 2>&1 | aptitude update >> ${tmpfile} 2>&1 | ||
echo "" >> ${tmpfile} | echo "" >> ${tmpfile} | ||
echo "aptitude | echo "aptitude full-upgrade" >> ${tmpfile} | ||
aptitude -y | aptitude -y full-upgrade >> ${tmpfile} 2>&1 | ||
echo "" >> ${tmpfile} | echo "" >> ${tmpfile} | ||
echo "aptitude clean" >> ${tmpfile} | echo "aptitude clean" >> ${tmpfile} | ||
aptitude clean >> ${tmpfile} 2>&1 | aptitude clean >> ${tmpfile} 2>&1 | ||
mail -s "Aptitude cron $(date)" root < ${tmpfile} | mail -s "Aptitude cron $(date)" root < ${tmpfile} | ||
rm -f ${tmpfile} </nowiki></pre> | rm -f ${tmpfile} </nowiki></pre> | ||
第72行: | 第110行: | ||
# changes. | # changes. | ||
# | # | ||
# | # | ||
# variables to change | # variables to change | ||
# | # | ||
# address to send results to | # address to send results to | ||
# host name of smtp server | # host name of smtp server | ||
MAIL=mail.yourisp.com | MAIL=mail.yourisp.com | ||
# | # | ||
# script is below here (do not change) | # script is below here (do not change) | ||
# | # | ||
tmpfile=$(mktemp) | tmpfile=$(mktemp) | ||
# | # | ||
# smtp setup commands | # smtp setup commands | ||
# | # | ||
echo "helo $(hostname)" >> ${tmpfile} | echo "helo $(hostname)" >> ${tmpfile} | ||
echo "mail from: root@$(hostname)" >> ${tmpfile} | echo "mail from: root@$(hostname)" >> ${tmpfile} | ||
第91行: | 第136行: | ||
echo 'data'>> ${tmpfile} | echo 'data'>> ${tmpfile} | ||
echo "subject: Aptitude cron $(date)" >> ${tmpfile} | echo "subject: Aptitude cron $(date)" >> ${tmpfile} | ||
# | # | ||
# actually run aptitude to do the updates, logging its output | # actually run aptitude to do the updates, logging its output | ||
# | # | ||
echo "aptitude update" >> ${tmpfile} | echo "aptitude update" >> ${tmpfile} | ||
aptitude update >> ${tmpfile} 2>&1 | aptitude update >> ${tmpfile} 2>&1 | ||
echo "" >> ${tmpfile} | echo "" >> ${tmpfile} | ||
echo "aptitude | echo "aptitude full-upgrade" >> ${tmpfile} | ||
aptitude -y | aptitude -y full-upgrade >> ${tmpfile} 2>&1 | ||
echo "" >> ${tmpfile} | echo "" >> ${tmpfile} | ||
echo "aptitude clean" >> ${tmpfile} | echo "aptitude clean" >> ${tmpfile} | ||
aptitude clean >> ${tmpfile} 2>&1 | aptitude clean >> ${tmpfile} 2>&1 | ||
# | # | ||
# i get a lot of escaped new lines in my output. so the following | # i get a lot of escaped new lines in my output. so the following | ||
# removes them. this could be greatly improved | # removes them. this could be greatly improved | ||
tmpfile2=$(mktemp) | tmpfile2=$(mktemp) | ||
cat ${tmpfile} | sed 's/\r\r/\n/g'|sed 's/\r//g' > ${tmpfile2} | cat ${tmpfile} | sed 's/\r\r/\n/g'|sed 's/\r//g' > ${tmpfile2} | ||
mv ${tmpfile2} ${tmpfile} | mv ${tmpfile2} ${tmpfile} | ||
# | # | ||
# smtp close commands | # smtp close commands | ||
# | # | ||
echo >> ${tmpfile} | echo >> ${tmpfile} | ||
echo '.' >> ${tmpfile} | echo '.' >> ${tmpfile} | ||
echo 'quit' >> ${tmpfile} | echo 'quit' >> ${tmpfile} | ||
echo >> ${tmpfile} | echo >> ${tmpfile} | ||
# | # | ||
# now send the email (and ignore output) | # now send the email (and ignore output) | ||
# | # | ||
telnet $MAIL 25 < ${tmpfile} > /dev/null 2> /dev/null | telnet $MAIL 25 < ${tmpfile} > /dev/null 2> /dev/null | ||
# | # | ||
# and remove temp files | # and remove temp files | ||
# | # | ||
rm -f ${tmpfile} | rm -f ${tmpfile} | ||
</nowiki></pre> | </nowiki></pre> | ||
---- | ---- | ||
---- | |||
[[category:CategorySecurity]] | |||
[[category:UbuntuHelp]] | [[category:UbuntuHelp]] |
2010年5月19日 (三) 21:39的最新版本
文章出处: |
{{#if: | {{{2}}} | https://help.ubuntu.com/community/AutoWeeklyUpdateHowTo }} |
点击翻译: |
English {{#ifexist: {{#if: UbuntuHelp:AutoWeeklyUpdateHowTo | UbuntuHelp:AutoWeeklyUpdateHowTo | {{#if: | :}}AutoWeeklyUpdateHowTo}}/af | • {{#if: UbuntuHelp:AutoWeeklyUpdateHowTo|Afrikaans| [[::AutoWeeklyUpdateHowTo/af|Afrikaans]]}}|}} {{#ifexist: {{#if: UbuntuHelp:AutoWeeklyUpdateHowTo | UbuntuHelp:AutoWeeklyUpdateHowTo | {{#if: | :}}AutoWeeklyUpdateHowTo}}/ar | • {{#if: UbuntuHelp:AutoWeeklyUpdateHowTo|العربية| [[::AutoWeeklyUpdateHowTo/ar|العربية]]}}|}} {{#ifexist: {{#if: UbuntuHelp:AutoWeeklyUpdateHowTo | UbuntuHelp:AutoWeeklyUpdateHowTo | {{#if: | :}}AutoWeeklyUpdateHowTo}}/az | • {{#if: UbuntuHelp:AutoWeeklyUpdateHowTo|azərbaycanca| [[::AutoWeeklyUpdateHowTo/az|azərbaycanca]]}}|}} {{#ifexist: {{#if: UbuntuHelp:AutoWeeklyUpdateHowTo | UbuntuHelp:AutoWeeklyUpdateHowTo | {{#if: | :}}AutoWeeklyUpdateHowTo}}/bcc | • {{#if: UbuntuHelp:AutoWeeklyUpdateHowTo|جهلسری بلوچی| [[::AutoWeeklyUpdateHowTo/bcc|جهلسری بلوچی]]}}|}} {{#ifexist: {{#if: UbuntuHelp:AutoWeeklyUpdateHowTo | UbuntuHelp:AutoWeeklyUpdateHowTo | {{#if: | :}}AutoWeeklyUpdateHowTo}}/bg | • {{#if: UbuntuHelp:AutoWeeklyUpdateHowTo|български| [[::AutoWeeklyUpdateHowTo/bg|български]]}}|}} {{#ifexist: {{#if: UbuntuHelp:AutoWeeklyUpdateHowTo | UbuntuHelp:AutoWeeklyUpdateHowTo | {{#if: | :}}AutoWeeklyUpdateHowTo}}/br | • {{#if: UbuntuHelp:AutoWeeklyUpdateHowTo|brezhoneg| [[::AutoWeeklyUpdateHowTo/br|brezhoneg]]}}|}} {{#ifexist: {{#if: UbuntuHelp:AutoWeeklyUpdateHowTo | UbuntuHelp:AutoWeeklyUpdateHowTo | {{#if: | :}}AutoWeeklyUpdateHowTo}}/ca | • {{#if: UbuntuHelp:AutoWeeklyUpdateHowTo|català| [[::AutoWeeklyUpdateHowTo/ca|català]]}}|}} {{#ifexist: {{#if: UbuntuHelp:AutoWeeklyUpdateHowTo | UbuntuHelp:AutoWeeklyUpdateHowTo | {{#if: | :}}AutoWeeklyUpdateHowTo}}/cs | • {{#if: UbuntuHelp:AutoWeeklyUpdateHowTo|čeština| [[::AutoWeeklyUpdateHowTo/cs|čeština]]}}|}} {{#ifexist: {{#if: UbuntuHelp:AutoWeeklyUpdateHowTo | UbuntuHelp:AutoWeeklyUpdateHowTo | {{#if: | :}}AutoWeeklyUpdateHowTo}}/de | • {{#if: UbuntuHelp:AutoWeeklyUpdateHowTo|Deutsch| [[::AutoWeeklyUpdateHowTo/de|Deutsch]]}}|}} {{#ifexist: {{#if: UbuntuHelp:AutoWeeklyUpdateHowTo | UbuntuHelp:AutoWeeklyUpdateHowTo | {{#if: | :}}AutoWeeklyUpdateHowTo}}/el | • {{#if: UbuntuHelp:AutoWeeklyUpdateHowTo|Ελληνικά| [[::AutoWeeklyUpdateHowTo/el|Ελληνικά]]}}|}} {{#ifexist: {{#if: UbuntuHelp:AutoWeeklyUpdateHowTo | UbuntuHelp:AutoWeeklyUpdateHowTo | {{#if: | :}}AutoWeeklyUpdateHowTo}}/es | • {{#if: UbuntuHelp:AutoWeeklyUpdateHowTo|español| [[::AutoWeeklyUpdateHowTo/es|español]]}}|}} {{#ifexist: {{#if: UbuntuHelp:AutoWeeklyUpdateHowTo | UbuntuHelp:AutoWeeklyUpdateHowTo | {{#if: | :}}AutoWeeklyUpdateHowTo}}/fa | • {{#if: UbuntuHelp:AutoWeeklyUpdateHowTo|فارسی| [[::AutoWeeklyUpdateHowTo/fa|فارسی]]}}|}} {{#ifexist: {{#if: UbuntuHelp:AutoWeeklyUpdateHowTo | UbuntuHelp:AutoWeeklyUpdateHowTo | {{#if: | :}}AutoWeeklyUpdateHowTo}}/fi | • {{#if: UbuntuHelp:AutoWeeklyUpdateHowTo|suomi| [[::AutoWeeklyUpdateHowTo/fi|suomi]]}}|}} {{#ifexist: {{#if: UbuntuHelp:AutoWeeklyUpdateHowTo | UbuntuHelp:AutoWeeklyUpdateHowTo | {{#if: | :}}AutoWeeklyUpdateHowTo}}/fr | • {{#if: UbuntuHelp:AutoWeeklyUpdateHowTo|français| [[::AutoWeeklyUpdateHowTo/fr|français]]}}|}} {{#ifexist: {{#if: UbuntuHelp:AutoWeeklyUpdateHowTo | UbuntuHelp:AutoWeeklyUpdateHowTo | {{#if: | :}}AutoWeeklyUpdateHowTo}}/gu | • {{#if: UbuntuHelp:AutoWeeklyUpdateHowTo|ગુજરાતી| [[::AutoWeeklyUpdateHowTo/gu|ગુજરાતી]]}}|}} {{#ifexist: {{#if: UbuntuHelp:AutoWeeklyUpdateHowTo | UbuntuHelp:AutoWeeklyUpdateHowTo | {{#if: | :}}AutoWeeklyUpdateHowTo}}/he | • {{#if: UbuntuHelp:AutoWeeklyUpdateHowTo|עברית| [[::AutoWeeklyUpdateHowTo/he|עברית]]}}|}} {{#ifexist: {{#if: UbuntuHelp:AutoWeeklyUpdateHowTo | UbuntuHelp:AutoWeeklyUpdateHowTo | {{#if: | :}}AutoWeeklyUpdateHowTo}}/hu | • {{#if: UbuntuHelp:AutoWeeklyUpdateHowTo|magyar| [[::AutoWeeklyUpdateHowTo/hu|magyar]]}}|}} {{#ifexist: {{#if: UbuntuHelp:AutoWeeklyUpdateHowTo | UbuntuHelp:AutoWeeklyUpdateHowTo | {{#if: | :}}AutoWeeklyUpdateHowTo}}/id | • {{#if: UbuntuHelp:AutoWeeklyUpdateHowTo|Bahasa Indonesia| [[::AutoWeeklyUpdateHowTo/id|Bahasa Indonesia]]}}|}} {{#ifexist: {{#if: UbuntuHelp:AutoWeeklyUpdateHowTo | UbuntuHelp:AutoWeeklyUpdateHowTo | {{#if: | :}}AutoWeeklyUpdateHowTo}}/it | • {{#if: UbuntuHelp:AutoWeeklyUpdateHowTo|italiano| [[::AutoWeeklyUpdateHowTo/it|italiano]]}}|}} {{#ifexist: {{#if: UbuntuHelp:AutoWeeklyUpdateHowTo | UbuntuHelp:AutoWeeklyUpdateHowTo | {{#if: | :}}AutoWeeklyUpdateHowTo}}/ja | • {{#if: UbuntuHelp:AutoWeeklyUpdateHowTo|日本語| [[::AutoWeeklyUpdateHowTo/ja|日本語]]}}|}} {{#ifexist: {{#if: UbuntuHelp:AutoWeeklyUpdateHowTo | UbuntuHelp:AutoWeeklyUpdateHowTo | {{#if: | :}}AutoWeeklyUpdateHowTo}}/ko | • {{#if: UbuntuHelp:AutoWeeklyUpdateHowTo|한국어| [[::AutoWeeklyUpdateHowTo/ko|한국어]]}}|}} {{#ifexist: {{#if: UbuntuHelp:AutoWeeklyUpdateHowTo | UbuntuHelp:AutoWeeklyUpdateHowTo | {{#if: | :}}AutoWeeklyUpdateHowTo}}/ksh | • {{#if: UbuntuHelp:AutoWeeklyUpdateHowTo|Ripoarisch| [[::AutoWeeklyUpdateHowTo/ksh|Ripoarisch]]}}|}} {{#ifexist: {{#if: UbuntuHelp:AutoWeeklyUpdateHowTo | UbuntuHelp:AutoWeeklyUpdateHowTo | {{#if: | :}}AutoWeeklyUpdateHowTo}}/mr | • {{#if: UbuntuHelp:AutoWeeklyUpdateHowTo|मराठी| [[::AutoWeeklyUpdateHowTo/mr|मराठी]]}}|}} {{#ifexist: {{#if: UbuntuHelp:AutoWeeklyUpdateHowTo | UbuntuHelp:AutoWeeklyUpdateHowTo | {{#if: | :}}AutoWeeklyUpdateHowTo}}/ms | • {{#if: UbuntuHelp:AutoWeeklyUpdateHowTo|Bahasa Melayu| [[::AutoWeeklyUpdateHowTo/ms|Bahasa Melayu]]}}|}} {{#ifexist: {{#if: UbuntuHelp:AutoWeeklyUpdateHowTo | UbuntuHelp:AutoWeeklyUpdateHowTo | {{#if: | :}}AutoWeeklyUpdateHowTo}}/nl | • {{#if: UbuntuHelp:AutoWeeklyUpdateHowTo|Nederlands| [[::AutoWeeklyUpdateHowTo/nl|Nederlands]]}}|}} {{#ifexist: {{#if: UbuntuHelp:AutoWeeklyUpdateHowTo | UbuntuHelp:AutoWeeklyUpdateHowTo | {{#if: | :}}AutoWeeklyUpdateHowTo}}/no | • {{#if: UbuntuHelp:AutoWeeklyUpdateHowTo|norsk| [[::AutoWeeklyUpdateHowTo/no|norsk]]}}|}} {{#ifexist: {{#if: UbuntuHelp:AutoWeeklyUpdateHowTo | UbuntuHelp:AutoWeeklyUpdateHowTo | {{#if: | :}}AutoWeeklyUpdateHowTo}}/oc | • {{#if: UbuntuHelp:AutoWeeklyUpdateHowTo|occitan| [[::AutoWeeklyUpdateHowTo/oc|occitan]]}}|}} {{#ifexist: {{#if: UbuntuHelp:AutoWeeklyUpdateHowTo | UbuntuHelp:AutoWeeklyUpdateHowTo | {{#if: | :}}AutoWeeklyUpdateHowTo}}/pl | • {{#if: UbuntuHelp:AutoWeeklyUpdateHowTo|polski| [[::AutoWeeklyUpdateHowTo/pl|polski]]}}|}} {{#ifexist: {{#if: UbuntuHelp:AutoWeeklyUpdateHowTo | UbuntuHelp:AutoWeeklyUpdateHowTo | {{#if: | :}}AutoWeeklyUpdateHowTo}}/pt | • {{#if: UbuntuHelp:AutoWeeklyUpdateHowTo|português| [[::AutoWeeklyUpdateHowTo/pt|português]]}}|}} {{#ifexist: {{#if: UbuntuHelp:AutoWeeklyUpdateHowTo | UbuntuHelp:AutoWeeklyUpdateHowTo | {{#if: | :}}AutoWeeklyUpdateHowTo}}/ro | • {{#if: UbuntuHelp:AutoWeeklyUpdateHowTo|română| [[::AutoWeeklyUpdateHowTo/ro|română]]}}|}} {{#ifexist: {{#if: UbuntuHelp:AutoWeeklyUpdateHowTo | UbuntuHelp:AutoWeeklyUpdateHowTo | {{#if: | :}}AutoWeeklyUpdateHowTo}}/ru | • {{#if: UbuntuHelp:AutoWeeklyUpdateHowTo|русский| [[::AutoWeeklyUpdateHowTo/ru|русский]]}}|}} {{#ifexist: {{#if: UbuntuHelp:AutoWeeklyUpdateHowTo | UbuntuHelp:AutoWeeklyUpdateHowTo | {{#if: | :}}AutoWeeklyUpdateHowTo}}/si | • {{#if: UbuntuHelp:AutoWeeklyUpdateHowTo|සිංහල| [[::AutoWeeklyUpdateHowTo/si|සිංහල]]}}|}} {{#ifexist: {{#if: UbuntuHelp:AutoWeeklyUpdateHowTo | UbuntuHelp:AutoWeeklyUpdateHowTo | {{#if: | :}}AutoWeeklyUpdateHowTo}}/sq | • {{#if: UbuntuHelp:AutoWeeklyUpdateHowTo|shqip| [[::AutoWeeklyUpdateHowTo/sq|shqip]]}}|}} {{#ifexist: {{#if: UbuntuHelp:AutoWeeklyUpdateHowTo | UbuntuHelp:AutoWeeklyUpdateHowTo | {{#if: | :}}AutoWeeklyUpdateHowTo}}/sr | • {{#if: UbuntuHelp:AutoWeeklyUpdateHowTo|српски / srpski| [[::AutoWeeklyUpdateHowTo/sr|српски / srpski]]}}|}} {{#ifexist: {{#if: UbuntuHelp:AutoWeeklyUpdateHowTo | UbuntuHelp:AutoWeeklyUpdateHowTo | {{#if: | :}}AutoWeeklyUpdateHowTo}}/sv | • {{#if: UbuntuHelp:AutoWeeklyUpdateHowTo|svenska| [[::AutoWeeklyUpdateHowTo/sv|svenska]]}}|}} {{#ifexist: {{#if: UbuntuHelp:AutoWeeklyUpdateHowTo | UbuntuHelp:AutoWeeklyUpdateHowTo | {{#if: | :}}AutoWeeklyUpdateHowTo}}/th | • {{#if: UbuntuHelp:AutoWeeklyUpdateHowTo|ไทย| [[::AutoWeeklyUpdateHowTo/th|ไทย]]}}|}} {{#ifexist: {{#if: UbuntuHelp:AutoWeeklyUpdateHowTo | UbuntuHelp:AutoWeeklyUpdateHowTo | {{#if: | :}}AutoWeeklyUpdateHowTo}}/tr | • {{#if: UbuntuHelp:AutoWeeklyUpdateHowTo|Türkçe| [[::AutoWeeklyUpdateHowTo/tr|Türkçe]]}}|}} {{#ifexist: {{#if: UbuntuHelp:AutoWeeklyUpdateHowTo | UbuntuHelp:AutoWeeklyUpdateHowTo | {{#if: | :}}AutoWeeklyUpdateHowTo}}/vi | • {{#if: UbuntuHelp:AutoWeeklyUpdateHowTo|Tiếng Việt| [[::AutoWeeklyUpdateHowTo/vi|Tiếng Việt]]}}|}} {{#ifexist: {{#if: UbuntuHelp:AutoWeeklyUpdateHowTo | UbuntuHelp:AutoWeeklyUpdateHowTo | {{#if: | :}}AutoWeeklyUpdateHowTo}}/yue | • {{#if: UbuntuHelp:AutoWeeklyUpdateHowTo|粵語| [[::AutoWeeklyUpdateHowTo/yue|粵語]]}}|}} {{#ifexist: {{#if: UbuntuHelp:AutoWeeklyUpdateHowTo | UbuntuHelp:AutoWeeklyUpdateHowTo | {{#if: | :}}AutoWeeklyUpdateHowTo}}/zh | • {{#if: UbuntuHelp:AutoWeeklyUpdateHowTo|中文| [[::AutoWeeklyUpdateHowTo/zh|中文]]}}|}} {{#ifexist: {{#if: UbuntuHelp:AutoWeeklyUpdateHowTo | UbuntuHelp:AutoWeeklyUpdateHowTo | {{#if: | :}}AutoWeeklyUpdateHowTo}}/zh-hans | • {{#if: UbuntuHelp:AutoWeeklyUpdateHowTo|中文(简体)| [[::AutoWeeklyUpdateHowTo/zh-hans|中文(简体)]]}}|}} {{#ifexist: {{#if: UbuntuHelp:AutoWeeklyUpdateHowTo | UbuntuHelp:AutoWeeklyUpdateHowTo | {{#if: | :}}AutoWeeklyUpdateHowTo}}/zh-hant | • {{#if: UbuntuHelp:AutoWeeklyUpdateHowTo|中文(繁體)| [[::AutoWeeklyUpdateHowTo/zh-hant|中文(繁體)]]}}|}} |
{{#ifeq:UbuntuHelp:AutoWeeklyUpdateHowTo|:AutoWeeklyUpdateHowTo|请不要直接编辑翻译本页,本页将定期与来源同步。}} |
{{#ifexist: :AutoWeeklyUpdateHowTo/zh | | {{#ifexist: AutoWeeklyUpdateHowTo/zh | | {{#ifeq: {{#titleparts:AutoWeeklyUpdateHowTo|1|-1|}} | zh | | }} }} }} {{#ifeq: {{#titleparts:AutoWeeklyUpdateHowTo|1|-1|}} | zh | | }}
Automatic Package Updates Using cron-apt
Desktop method - default
If you have installed the full desktop version of Ubuntu, everything you need is already installed and running. Package updates can be scheduled from the desktop. You can change how and when the system updates itself. Click System, Administration, Software Sources. You will be prompted for your password. Once you've entered that, click Updates. You'll see various categories of updates, and underneath Automatic Updates, you'll see Check for updates: and a schedule. You can select daily, weekly, manually etc. You can also select whether you wish the system to:
- Install security updates without confirmation (ie. download and install)
- Download all updates in the background (ie. download but wait for you to manually install them)
- Only notify about available updates (ie. nag you to manually download updates and to manually install them)
The default is to check daily and notify you. A down-arrow will appear in the desktop notification tray when updates are available, accompanied by a pop-up bubble telling you that updates are available. When it appears, click it, and it will guide you through the update process. That's it, all done. You do not need to install cron-apt yourself and you can stop reading this page now, safe in the knowledge that your system is receiving the latest security updates and fixes. Of course, it never hurts to learn...
cron-apt method
This method is for people who have installed a cut-down, customised or server version of Ubuntu. If you have installed the full desktop version of Ubuntu, updates are automatically handled by the GUI method described above. There is no need to install cron-apt yourself if you are running the full desktop version of Ubuntu. But the whole point of Linux and open source software is that you can customise it, right? The package cron-apt is designed to automatically update the package list and download upgraded packages. Therefore it basically calls the command
apt-get update
Installing Cron-apt
You can get cron-apt from the Universe Repositories using Synaptic, or from the command line:
sudo apt-get install cron-apt
By default, cron-apt will execute automatically at 4am. If your system is normally turned off at 4am, you can either edit /etc/cron.d/cron-apt and change the schedule to a time when your PC is likely to be switched on, or you can use Anacron to make it run when your PC is next turned on.
Making cron-apt execute regularly with Anacron
Anacron makes sure that all the tasks listed in /etc/cron.hourly , /etc/cron.daily , /etc/cron.weekly and /etc/cron.monthly are performed, even if the PC is switched off when they'd normally happen. Overdue tasks are run when the computer is next turned on. On the good side, it never misses a task. On the bad side, if the tasks take a lot of time, your PC might seem a little slow when you first turn it on after a long time being turned off.
Optional: Comment out cron-apt
Anacron does not look in /etc/cron.d . You may wish to comment out the line in /etc/cron.d/cron-apt which would otherwise cause it to run at 4am. It won't do any harm to leave it there (you can run cron-apt many times a day without problems), but why would you need to run it both in cron.d and cron.daily or cron.weekly? For the sake of tidyness you can prefix the line:
0 4 * * * root test -x /usr/sbin/cron-apt && /usr-sbin/cron-apt
...with a # , which will prevent it from executing at 4am:
{ # 0 4 * * * root test -x /usr/sbin/cron-apt && /usr-sbin/cron-apt
}
Add cron-apt to cron.daily
To make cron-apt be executed by Anacron, create a link in /etc/cron.daily or /etc/cron.weekly. For example:
sudo ln -s /usr/sbin/cron-apt /etc/cron.weekly/
Manually apply the updates
Cron-apt only downloads new packages. If you are a desktop user, you will be notified that there are updates waiting by a down-arrow icon in the notification area (it will not appear until there are updates ready). Click this and it will prompt you through the update process. Alternatively, from the command line you can do:
sudo apt-get dist-upgrade
Advanced Alternatives
Below are alternatives to using cron-apt, for advanced users only. You should use them instead of cron-apt, but there is no point doing them in addition cron-apt. You can remove cron-apt with:
sudo apt-get remove cron-apt
Advanced Alternative: Automatic Weekly Package Updates Using Cron And Apt-Get
WARNING: As with any system changes, the potential for creating new or additional problems may occur. Please be sure to backup your data and configurations! Use this document at your own risk. Keeping your Ubuntu (or Debian based) system packages regularly updated not only helps to better secure your system, but also helps keep it running bug free. This howto discusses how to setup a very easy and simple Cron job on your system that will update your system packages weekly, and remove any old unused packages no longer installed after updating. (This document assumes an always or mostly always on system with a broadband, not dial-up, Internet connection.)
Creating the Weekly Cron Job File
First you will need to create the cron job file. You can use a simple text editor to create the file and save it in your home directory. In Ubuntu, open Applications > Accessories > Text Editor. In the Text Editor, type the following lines:
#!/bin/bash apt-get update apt-get upgrade -y apt-get autoclean
Now click Save and name the file something like "autoupdt". The default directory should be your home directory, but verify to be certain. (The steps following this will assume the file has been saved in your home directory.)
Moving the Cron Job File to Cron.Weekly
Now that you have created the cron job file, it needs to be moved into the weekly cron directory so that it will be run automatically on a weekly basis. To do this, we first need to open a command line terminal. In Ubuntu, click Applications > System Tools > Terminal. Now you should see your terminal prompt. At the prompt type "ls" and press Enter (or Return on some keyboards). In the list you should see your newly created file "autoupdt".
user@system:~$cd ~ user@system:~$ls
Now that we know the file is there, we need to move the file to the proper directory. Type the following command at the command line promt to move the file:
user@system:~$sudo mv autoupdt /etc/cron.weekly
(You may be prompted to enter your sudo password, which is YOUR password.) Now we need to move to the Cron directory to verify the file was moved. At the command line prompt type:
user@system:~$cd /etc/cron.weekly user@system:~$ls
You should see the "autoupdt" file in the list. (If not, try the previous move command again.)
Making the Cron Job File Executable
Now that the file is created and ready to be run weekly by cron, we still need to make the file executable in order for cron to be able to run it. Since you are already in the cron.weekly directory, all you need to do is enter this command at the prompt:
user@system:~$sudo chmod 755 autoupdt
(Again you may be prompted for your sudo password.)
Finished
Now that the file is executable, you are finished. The cron job will run weekly and update your source list (to see if there are any new package updates), update your packages as found and needed, then clean out any old unused no longer installed packages. You can still update using Synaptic Package Manager or apt-get at the command line, but now you can relax a bit knowing your system will be updated automatically on a weekly basis.
Advanced Alternative: Package Updates with Logging using Aptitude
Apt-get doesn't write details of changes it makes to log files. Aptitude logs to /var/log/aptitude, and can mail a report to root, which can be redirected to the sudo user if Postfix is set up to do this. As with the examples above, create this script as /etc/cron.weekly/autoupdt and make it executable. We use here a special action of aptitude called 'full-upgrade' (which will always upgrade your packages to the latest version, before Ubuntu 7.10 it was called 'dist-upgrade'). However, you might want to have a more conservative action when doing this on a server, the action 'safe-upgrade' is there for you. You can check the guide on aptitude for more information: AptitudeSurvivalGuide.
#!/bin/bash tmpfile=$(mktemp) echo "aptitude update" >> ${tmpfile} aptitude update >> ${tmpfile} 2>&1 echo "" >> ${tmpfile} echo "aptitude full-upgrade" >> ${tmpfile} aptitude -y full-upgrade >> ${tmpfile} 2>&1 echo "" >> ${tmpfile} echo "aptitude clean" >> ${tmpfile} aptitude clean >> ${tmpfile} 2>&1 mail -s "Aptitude cron $(date)" root < ${tmpfile} rm -f ${tmpfile}
Here is a script (based on the above) that is useful if you don't have sendmail or postfix installed on your computer. It collects all the output from aptitude and manually sends an email using a mail server you specify. You must also specify the recipient of the email. As with the examples above, create this script as /etc/cron.weekly/autoupdt and make it executable:
#!/bin/bash # # use aptitude to automatically install updates. log and email any # changes. # # # variables to change # # address to send results to [email protected] # host name of smtp server MAIL=mail.yourisp.com # # script is below here (do not change) # tmpfile=$(mktemp) # # smtp setup commands # echo "helo $(hostname)" >> ${tmpfile} echo "mail from: root@$(hostname)" >> ${tmpfile} echo "rcpt to: $MAILTO" >> ${tmpfile} echo 'data'>> ${tmpfile} echo "subject: Aptitude cron $(date)" >> ${tmpfile} # # actually run aptitude to do the updates, logging its output # echo "aptitude update" >> ${tmpfile} aptitude update >> ${tmpfile} 2>&1 echo "" >> ${tmpfile} echo "aptitude full-upgrade" >> ${tmpfile} aptitude -y full-upgrade >> ${tmpfile} 2>&1 echo "" >> ${tmpfile} echo "aptitude clean" >> ${tmpfile} aptitude clean >> ${tmpfile} 2>&1 # # i get a lot of escaped new lines in my output. so the following # removes them. this could be greatly improved tmpfile2=$(mktemp) cat ${tmpfile} | sed 's/\r\r/\n/g'|sed 's/\r//g' > ${tmpfile2} mv ${tmpfile2} ${tmpfile} # # smtp close commands # echo >> ${tmpfile} echo '.' >> ${tmpfile} echo 'quit' >> ${tmpfile} echo >> ${tmpfile} # # now send the email (and ignore output) # telnet $MAIL 25 < ${tmpfile} > /dev/null 2> /dev/null # # and remove temp files # rm -f ${tmpfile}