.sh file for apt-get update/apt-get upgrade





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







1















This may be a simple question but...



I have an update.sh file with the following:



sudo apt-get update
sudo apt-get upgrade


When I run this using ./update.sh (after setting it to executable),
it asks me to enter my sudo password. Will this run both commands, and I can essentially only run this script once and have my apt-get update/upgrade commands taken care of?



Thanks everyone










share|improve this question























  • Your script should ask for your password only once while runing both commands. Note that as written, the script is interactive - it will ask you questions and wait for your response, even if you're not there. Er, Ubuntu does ship with unattended-upgrades, which does all this for you, if you wish.

    – user535733
    Apr 29 '17 at 17:38













  • could you give some more details on what you mean? I'm just trying to only have to run one command for both update/upgrade. I'm not too familiar with bash scripts and the like.

    – snovosel
    Apr 29 '17 at 18:05











  • apt already has a feature to update/upgrade daily. It's called unattended-upgrades, and it's included with all flavors with Ubuntu. You need to understand a bit about how packages and repositories work (which is good - you need to know that anyway). The settings for unattended-upgrades are within apt: /etc/apt/apt.conf.d/

    – user535733
    Apr 29 '17 at 19:54











  • is there documentation for this?

    – snovosel
    Apr 29 '17 at 22:18











  • Yes, each setting is explained within the files themselves. Be aware that apt will do exactly what you tell it to do, regardless of your actual intent. For example, updating from non-Ubuntu repos and PPAs can be quite unwise.

    – user535733
    Apr 29 '17 at 22:43


















1















This may be a simple question but...



I have an update.sh file with the following:



sudo apt-get update
sudo apt-get upgrade


When I run this using ./update.sh (after setting it to executable),
it asks me to enter my sudo password. Will this run both commands, and I can essentially only run this script once and have my apt-get update/upgrade commands taken care of?



Thanks everyone










share|improve this question























  • Your script should ask for your password only once while runing both commands. Note that as written, the script is interactive - it will ask you questions and wait for your response, even if you're not there. Er, Ubuntu does ship with unattended-upgrades, which does all this for you, if you wish.

    – user535733
    Apr 29 '17 at 17:38













  • could you give some more details on what you mean? I'm just trying to only have to run one command for both update/upgrade. I'm not too familiar with bash scripts and the like.

    – snovosel
    Apr 29 '17 at 18:05











  • apt already has a feature to update/upgrade daily. It's called unattended-upgrades, and it's included with all flavors with Ubuntu. You need to understand a bit about how packages and repositories work (which is good - you need to know that anyway). The settings for unattended-upgrades are within apt: /etc/apt/apt.conf.d/

    – user535733
    Apr 29 '17 at 19:54











  • is there documentation for this?

    – snovosel
    Apr 29 '17 at 22:18











  • Yes, each setting is explained within the files themselves. Be aware that apt will do exactly what you tell it to do, regardless of your actual intent. For example, updating from non-Ubuntu repos and PPAs can be quite unwise.

    – user535733
    Apr 29 '17 at 22:43














1












1








1








This may be a simple question but...



I have an update.sh file with the following:



sudo apt-get update
sudo apt-get upgrade


When I run this using ./update.sh (after setting it to executable),
it asks me to enter my sudo password. Will this run both commands, and I can essentially only run this script once and have my apt-get update/upgrade commands taken care of?



Thanks everyone










share|improve this question














This may be a simple question but...



I have an update.sh file with the following:



sudo apt-get update
sudo apt-get upgrade


When I run this using ./update.sh (after setting it to executable),
it asks me to enter my sudo password. Will this run both commands, and I can essentially only run this script once and have my apt-get update/upgrade commands taken care of?



Thanks everyone







command-line apt bash upgrade






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Apr 29 '17 at 17:07









snovoselsnovosel

613




613













  • Your script should ask for your password only once while runing both commands. Note that as written, the script is interactive - it will ask you questions and wait for your response, even if you're not there. Er, Ubuntu does ship with unattended-upgrades, which does all this for you, if you wish.

    – user535733
    Apr 29 '17 at 17:38













  • could you give some more details on what you mean? I'm just trying to only have to run one command for both update/upgrade. I'm not too familiar with bash scripts and the like.

    – snovosel
    Apr 29 '17 at 18:05











  • apt already has a feature to update/upgrade daily. It's called unattended-upgrades, and it's included with all flavors with Ubuntu. You need to understand a bit about how packages and repositories work (which is good - you need to know that anyway). The settings for unattended-upgrades are within apt: /etc/apt/apt.conf.d/

    – user535733
    Apr 29 '17 at 19:54











  • is there documentation for this?

    – snovosel
    Apr 29 '17 at 22:18











  • Yes, each setting is explained within the files themselves. Be aware that apt will do exactly what you tell it to do, regardless of your actual intent. For example, updating from non-Ubuntu repos and PPAs can be quite unwise.

    – user535733
    Apr 29 '17 at 22:43



















  • Your script should ask for your password only once while runing both commands. Note that as written, the script is interactive - it will ask you questions and wait for your response, even if you're not there. Er, Ubuntu does ship with unattended-upgrades, which does all this for you, if you wish.

    – user535733
    Apr 29 '17 at 17:38













  • could you give some more details on what you mean? I'm just trying to only have to run one command for both update/upgrade. I'm not too familiar with bash scripts and the like.

    – snovosel
    Apr 29 '17 at 18:05











  • apt already has a feature to update/upgrade daily. It's called unattended-upgrades, and it's included with all flavors with Ubuntu. You need to understand a bit about how packages and repositories work (which is good - you need to know that anyway). The settings for unattended-upgrades are within apt: /etc/apt/apt.conf.d/

    – user535733
    Apr 29 '17 at 19:54











  • is there documentation for this?

    – snovosel
    Apr 29 '17 at 22:18











  • Yes, each setting is explained within the files themselves. Be aware that apt will do exactly what you tell it to do, regardless of your actual intent. For example, updating from non-Ubuntu repos and PPAs can be quite unwise.

    – user535733
    Apr 29 '17 at 22:43

















Your script should ask for your password only once while runing both commands. Note that as written, the script is interactive - it will ask you questions and wait for your response, even if you're not there. Er, Ubuntu does ship with unattended-upgrades, which does all this for you, if you wish.

– user535733
Apr 29 '17 at 17:38







Your script should ask for your password only once while runing both commands. Note that as written, the script is interactive - it will ask you questions and wait for your response, even if you're not there. Er, Ubuntu does ship with unattended-upgrades, which does all this for you, if you wish.

– user535733
Apr 29 '17 at 17:38















could you give some more details on what you mean? I'm just trying to only have to run one command for both update/upgrade. I'm not too familiar with bash scripts and the like.

– snovosel
Apr 29 '17 at 18:05





could you give some more details on what you mean? I'm just trying to only have to run one command for both update/upgrade. I'm not too familiar with bash scripts and the like.

– snovosel
Apr 29 '17 at 18:05













apt already has a feature to update/upgrade daily. It's called unattended-upgrades, and it's included with all flavors with Ubuntu. You need to understand a bit about how packages and repositories work (which is good - you need to know that anyway). The settings for unattended-upgrades are within apt: /etc/apt/apt.conf.d/

– user535733
Apr 29 '17 at 19:54





apt already has a feature to update/upgrade daily. It's called unattended-upgrades, and it's included with all flavors with Ubuntu. You need to understand a bit about how packages and repositories work (which is good - you need to know that anyway). The settings for unattended-upgrades are within apt: /etc/apt/apt.conf.d/

– user535733
Apr 29 '17 at 19:54













is there documentation for this?

– snovosel
Apr 29 '17 at 22:18





is there documentation for this?

– snovosel
Apr 29 '17 at 22:18













Yes, each setting is explained within the files themselves. Be aware that apt will do exactly what you tell it to do, regardless of your actual intent. For example, updating from non-Ubuntu repos and PPAs can be quite unwise.

– user535733
Apr 29 '17 at 22:43





Yes, each setting is explained within the files themselves. Be aware that apt will do exactly what you tell it to do, regardless of your actual intent. For example, updating from non-Ubuntu repos and PPAs can be quite unwise.

– user535733
Apr 29 '17 at 22:43










3 Answers
3






active

oldest

votes


















3














The way sudo works is that by default it gives you 15 minutes before it will ask for password again. So yes, using the two commands, will work perfectly fine, and depending on how long apt-get update runs you will need to enter password once.



However, this is not the best practice. Instead, I would suggest making your whole script run with sudo instead of placing it in front of each command in file. In other words, the script should be:



#!/bin/bash
apt-get update
apt-get upgrade


And run it as



sudo  ./my_script.sh


Notice that here we're using #!/bin/bash line to use bash shell as interpreter. This is very different from /bin/sh. For what you're doing it makes no difference, but if you need to be aware that they differ in syntax of some of the operators.



However, even better approach would be to get rid of script altogether and use function or alias that does what you want. Scripts are really for large amounts of code that you want to reuse. For 2 - 3 lines a function or alias in ~/.bashrc file that's going to be sufficient.



Personally I'd make something like this in my ~/.bashrc



alias agu="sudo bash -c 'apt-get update && apt-get upgrade'"





share|improve this answer































    1














    Don't forget to set DEBIAN_FRONTEND=noninteractive for those pesky prompts about which version to maintain:



    sudo DEBIAN_FRONTEND=noninteractive apt-get upgrade -y;


    If you don't do this your script will hang in patching limbo. So if you were going to do this in a script I would do the following:



    #!/usr/bin/env bash
    set -e

    patching(){
    # sudo specified because this was from my bootstrap script for an
    # ec2 instance remove the sudos as previously stated if you are
    # going to exec it from your current shell
    sudo apt-get update -y;
    sudo DEBIAN_FRONTEND=noninteractive apt-get upgrade -y;
    };

    patching;


    The previously stated methods will work... until they don't.



    I had to refer back to a previous script that I wrote to find this variable.



    Hopefully, it helps someone else with their patching/bootstrap script.






    share|improve this answer































      0














      Why not simply run:



      apt-get update && apt-get upgrade





      share|improve this answer
























        Your Answer








        StackExchange.ready(function() {
        var channelOptions = {
        tags: "".split(" "),
        id: "89"
        };
        initTagRenderer("".split(" "), "".split(" "), channelOptions);

        StackExchange.using("externalEditor", function() {
        // Have to fire editor after snippets, if snippets enabled
        if (StackExchange.settings.snippets.snippetsEnabled) {
        StackExchange.using("snippets", function() {
        createEditor();
        });
        }
        else {
        createEditor();
        }
        });

        function createEditor() {
        StackExchange.prepareEditor({
        heartbeatType: 'answer',
        autoActivateHeartbeat: false,
        convertImagesToLinks: true,
        noModals: true,
        showLowRepImageUploadWarning: true,
        reputationToPostImages: 10,
        bindNavPrevention: true,
        postfix: "",
        imageUploader: {
        brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
        contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
        allowUrls: true
        },
        onDemand: true,
        discardSelector: ".discard-answer"
        ,immediatelyShowMarkdownHelp:true
        });


        }
        });














        draft saved

        draft discarded


















        StackExchange.ready(
        function () {
        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f910245%2fsh-file-for-apt-get-update-apt-get-upgrade%23new-answer', 'question_page');
        }
        );

        Post as a guest















        Required, but never shown

























        3 Answers
        3






        active

        oldest

        votes








        3 Answers
        3






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes









        3














        The way sudo works is that by default it gives you 15 minutes before it will ask for password again. So yes, using the two commands, will work perfectly fine, and depending on how long apt-get update runs you will need to enter password once.



        However, this is not the best practice. Instead, I would suggest making your whole script run with sudo instead of placing it in front of each command in file. In other words, the script should be:



        #!/bin/bash
        apt-get update
        apt-get upgrade


        And run it as



        sudo  ./my_script.sh


        Notice that here we're using #!/bin/bash line to use bash shell as interpreter. This is very different from /bin/sh. For what you're doing it makes no difference, but if you need to be aware that they differ in syntax of some of the operators.



        However, even better approach would be to get rid of script altogether and use function or alias that does what you want. Scripts are really for large amounts of code that you want to reuse. For 2 - 3 lines a function or alias in ~/.bashrc file that's going to be sufficient.



        Personally I'd make something like this in my ~/.bashrc



        alias agu="sudo bash -c 'apt-get update && apt-get upgrade'"





        share|improve this answer




























          3














          The way sudo works is that by default it gives you 15 minutes before it will ask for password again. So yes, using the two commands, will work perfectly fine, and depending on how long apt-get update runs you will need to enter password once.



          However, this is not the best practice. Instead, I would suggest making your whole script run with sudo instead of placing it in front of each command in file. In other words, the script should be:



          #!/bin/bash
          apt-get update
          apt-get upgrade


          And run it as



          sudo  ./my_script.sh


          Notice that here we're using #!/bin/bash line to use bash shell as interpreter. This is very different from /bin/sh. For what you're doing it makes no difference, but if you need to be aware that they differ in syntax of some of the operators.



          However, even better approach would be to get rid of script altogether and use function or alias that does what you want. Scripts are really for large amounts of code that you want to reuse. For 2 - 3 lines a function or alias in ~/.bashrc file that's going to be sufficient.



          Personally I'd make something like this in my ~/.bashrc



          alias agu="sudo bash -c 'apt-get update && apt-get upgrade'"





          share|improve this answer


























            3












            3








            3







            The way sudo works is that by default it gives you 15 minutes before it will ask for password again. So yes, using the two commands, will work perfectly fine, and depending on how long apt-get update runs you will need to enter password once.



            However, this is not the best practice. Instead, I would suggest making your whole script run with sudo instead of placing it in front of each command in file. In other words, the script should be:



            #!/bin/bash
            apt-get update
            apt-get upgrade


            And run it as



            sudo  ./my_script.sh


            Notice that here we're using #!/bin/bash line to use bash shell as interpreter. This is very different from /bin/sh. For what you're doing it makes no difference, but if you need to be aware that they differ in syntax of some of the operators.



            However, even better approach would be to get rid of script altogether and use function or alias that does what you want. Scripts are really for large amounts of code that you want to reuse. For 2 - 3 lines a function or alias in ~/.bashrc file that's going to be sufficient.



            Personally I'd make something like this in my ~/.bashrc



            alias agu="sudo bash -c 'apt-get update && apt-get upgrade'"





            share|improve this answer













            The way sudo works is that by default it gives you 15 minutes before it will ask for password again. So yes, using the two commands, will work perfectly fine, and depending on how long apt-get update runs you will need to enter password once.



            However, this is not the best practice. Instead, I would suggest making your whole script run with sudo instead of placing it in front of each command in file. In other words, the script should be:



            #!/bin/bash
            apt-get update
            apt-get upgrade


            And run it as



            sudo  ./my_script.sh


            Notice that here we're using #!/bin/bash line to use bash shell as interpreter. This is very different from /bin/sh. For what you're doing it makes no difference, but if you need to be aware that they differ in syntax of some of the operators.



            However, even better approach would be to get rid of script altogether and use function or alias that does what you want. Scripts are really for large amounts of code that you want to reuse. For 2 - 3 lines a function or alias in ~/.bashrc file that's going to be sufficient.



            Personally I'd make something like this in my ~/.bashrc



            alias agu="sudo bash -c 'apt-get update && apt-get upgrade'"






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Jun 2 '17 at 17:49









            Sergiy KolodyazhnyySergiy Kolodyazhnyy

            75.6k9156331




            75.6k9156331

























                1














                Don't forget to set DEBIAN_FRONTEND=noninteractive for those pesky prompts about which version to maintain:



                sudo DEBIAN_FRONTEND=noninteractive apt-get upgrade -y;


                If you don't do this your script will hang in patching limbo. So if you were going to do this in a script I would do the following:



                #!/usr/bin/env bash
                set -e

                patching(){
                # sudo specified because this was from my bootstrap script for an
                # ec2 instance remove the sudos as previously stated if you are
                # going to exec it from your current shell
                sudo apt-get update -y;
                sudo DEBIAN_FRONTEND=noninteractive apt-get upgrade -y;
                };

                patching;


                The previously stated methods will work... until they don't.



                I had to refer back to a previous script that I wrote to find this variable.



                Hopefully, it helps someone else with their patching/bootstrap script.






                share|improve this answer




























                  1














                  Don't forget to set DEBIAN_FRONTEND=noninteractive for those pesky prompts about which version to maintain:



                  sudo DEBIAN_FRONTEND=noninteractive apt-get upgrade -y;


                  If you don't do this your script will hang in patching limbo. So if you were going to do this in a script I would do the following:



                  #!/usr/bin/env bash
                  set -e

                  patching(){
                  # sudo specified because this was from my bootstrap script for an
                  # ec2 instance remove the sudos as previously stated if you are
                  # going to exec it from your current shell
                  sudo apt-get update -y;
                  sudo DEBIAN_FRONTEND=noninteractive apt-get upgrade -y;
                  };

                  patching;


                  The previously stated methods will work... until they don't.



                  I had to refer back to a previous script that I wrote to find this variable.



                  Hopefully, it helps someone else with their patching/bootstrap script.






                  share|improve this answer


























                    1












                    1








                    1







                    Don't forget to set DEBIAN_FRONTEND=noninteractive for those pesky prompts about which version to maintain:



                    sudo DEBIAN_FRONTEND=noninteractive apt-get upgrade -y;


                    If you don't do this your script will hang in patching limbo. So if you were going to do this in a script I would do the following:



                    #!/usr/bin/env bash
                    set -e

                    patching(){
                    # sudo specified because this was from my bootstrap script for an
                    # ec2 instance remove the sudos as previously stated if you are
                    # going to exec it from your current shell
                    sudo apt-get update -y;
                    sudo DEBIAN_FRONTEND=noninteractive apt-get upgrade -y;
                    };

                    patching;


                    The previously stated methods will work... until they don't.



                    I had to refer back to a previous script that I wrote to find this variable.



                    Hopefully, it helps someone else with their patching/bootstrap script.






                    share|improve this answer













                    Don't forget to set DEBIAN_FRONTEND=noninteractive for those pesky prompts about which version to maintain:



                    sudo DEBIAN_FRONTEND=noninteractive apt-get upgrade -y;


                    If you don't do this your script will hang in patching limbo. So if you were going to do this in a script I would do the following:



                    #!/usr/bin/env bash
                    set -e

                    patching(){
                    # sudo specified because this was from my bootstrap script for an
                    # ec2 instance remove the sudos as previously stated if you are
                    # going to exec it from your current shell
                    sudo apt-get update -y;
                    sudo DEBIAN_FRONTEND=noninteractive apt-get upgrade -y;
                    };

                    patching;


                    The previously stated methods will work... until they don't.



                    I had to refer back to a previous script that I wrote to find this variable.



                    Hopefully, it helps someone else with their patching/bootstrap script.







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Nov 3 '17 at 5:38









                    Robert JRobert J

                    111




                    111























                        0














                        Why not simply run:



                        apt-get update && apt-get upgrade





                        share|improve this answer




























                          0














                          Why not simply run:



                          apt-get update && apt-get upgrade





                          share|improve this answer


























                            0












                            0








                            0







                            Why not simply run:



                            apt-get update && apt-get upgrade





                            share|improve this answer













                            Why not simply run:



                            apt-get update && apt-get upgrade






                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Feb 14 at 12:48









                            VijayVijay

                            2,1342822




                            2,1342822






























                                draft saved

                                draft discarded




















































                                Thanks for contributing an answer to Ask Ubuntu!


                                • Please be sure to answer the question. Provide details and share your research!

                                But avoid



                                • Asking for help, clarification, or responding to other answers.

                                • Making statements based on opinion; back them up with references or personal experience.


                                To learn more, see our tips on writing great answers.




                                draft saved


                                draft discarded














                                StackExchange.ready(
                                function () {
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f910245%2fsh-file-for-apt-get-update-apt-get-upgrade%23new-answer', 'question_page');
                                }
                                );

                                Post as a guest















                                Required, but never shown





















































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown

































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown







                                Popular posts from this blog

                                Human spaceflight

                                Can not write log (Is /dev/pts mounted?) - openpty in Ubuntu-on-Windows?

                                File:DeusFollowingSea.jpg