0

I know that you can make it so that security updates are downloaded and installed automatically, but you seem to be unable to do this with other updates, also, I don't want them just to be installed at any time, I want to be able to set it up so that the machine automatically updates everything that needs updating at a set time each day. So I was wondering how this could be achieved, because I haven't seen any options which seem to enable anything like this?

Contextual Information:

This is not for my machine, but instead another machine which I am managing and cannot be on the whole time to update, but needs to be regularly updated without user intervention.

7
  • I run Terminal in my startup programs. My zsh .zshrc file runs a script that executes apt-get update, apt-get upgrade, apt-get dist-upgrade, apt-get autoclean. My system updater is rarely ever activated. To run unattended at boot-up and without password, you'll have to edit the sudoers file.
    – RCF
    Jul 11, 2015 at 12:57
  • @RCF-U15.04: What about the "[Y/n]" prompt? How is that dealt with in a script without user intervention?
    – user364819
    Jul 11, 2015 at 13:00
  • sudo apt-get update && sudo apt-get -y upgrade
    – RCF
    Jul 11, 2015 at 13:31
  • @RCF-U15.04: Could you please convert all that into an answer explaining how to add it to my startup programs and what the script contains that is executed etc... So that I can accept it.
    – user364819
    Jul 17, 2015 at 11:24
  • 1
    Does this answer your question? Set a scheduled time for software updates
    – user68186
    Jun 6, 2022 at 21:16

1 Answer 1

1

Open your favorite editor and create a script file similar to this:

#!/usr/local/bin/zsh  ### I use zsh, enter your shell here.
sudo apt-get -qq update
sudo apt-get -y -qq upgrade
exit                  ### Be sure to include this exit line

Make your Your_Script_File.sh executable.

chmod +x <your_script_file.sh>

Next, edit the sudoers file.

Open a terminal and enter

    sudo visudo

At the end of the file (really, the last line) add the following lines.

<user_name>  ALL=(ALL) NOPASSWD: /home/<user_name>/script_name.sh
<user_name>  ALL=(ALL) NOPASSWD: /usr/bin/apt-get -qq update
<user_name>  ALL=(ALL) NOPASSWD: /usr/bin/apt-get -y -qq upgrade

After that you won't be prompted for a password for the commands listed. These lines should include the exact commands used in your script. You will no longer be prompted for a password, and the -qq eliminates the scrolling output in the terminal window. Please understand this is a very risky solution, there is a reason why you need to type a password for some commands, the use of these commands without password can leave your system open for some dangers. Use with caution. I like the -qq option because it is rarely used by most users and if they run

sudo apt-get update

The system will require a password.

Next, ALT + F2 open Startup Applications.

This will run the Startup Applications Preferences dialog window. Click Add. Give it a name, I used "startUpdate". In the Command box enter the command

    xterm -e ./<your_script_name

Xterm recognizes the exit from the script and will close the window, when execution is complete.

The user will see a blank xterm window for a couple of minutes, then it closes.

Hope this works for you.

You must log in to answer this question.