• Bash Script for Updating


    SO, I don’t really know if this is the right spot or not, but I think this is a fairly newbie type question here, so this is where I thought I would post it:slight_smile:.

    Anyways, this is my issue: I have a script to update Antergos, but I have some added functionalities that it runs afterwards (such as cleaning the cache). So I thought, what if I used an if statement to make it update when updates were available and skip that and go to cleaning the system when they weren’t. Apparently this is harder than I though:smile:. This is the if statement I have so far, but it does not seem to be working quite right.

    if ((" checkupdates | wc -l" = 0))
    then
         echo "THERE IS NOTHING TO UPDATE"
    else
         echo "NEW PACKAGES AVAILABLE"
         echo "YOUR SYSTEM IS ABOUT TO BE FULLY UPDATED"
        | yes | sudo fetchmirrors --country US
         echo
         echo
         echo "my_root_password" | sudo -S pacman -Syu --noconfirm
         yaourt -Syu --aur --noconfirm
    fi;
    

    If anyone has any suggestions as to how I could fix it up or what I did wrong, that would be appreciated.

    Thank you for all of your help in advance!

    Keep trying, never give up. In the end, you will find that it was all worth it

    Community ISO: https://antergoscommunityeditions.wordpress.com
    Linux Basics: https://linuxbasicssite.wordpress.com

  • script.sh:

    #!/bin/sh 
    
    nupdates=`checkupdates | wc -l`
    
    if [ $nupdates = "0" ]
    then
         echo "THERE IS NOTHING TO UPDATE"
    else
         echo $nupdates "NEW PACKAGES AVAILABLE"
         echo "YOUR SYSTEM IS ABOUT TO BE FULLY UPDATED"
         echo
         echo
         sudo pacman -Syu --noconfirm
         yaourt -Syu --aur --noconfirm
    fi;
    

    It is not a good idea to reveal your password in a script.

  • Thank you so much, @psscnp142:grinning:. I off to give the improved setup from your script a try!

    It is not a good idea to reveal your password in a script.

    Yeah, I suppose you’re right. However, I only use this for personal use, so its not available to anyone else. I think I will get rid of that though all the same like you advised…

    Keep trying, never give up. In the end, you will find that it was all worth it

    Community ISO: https://antergoscommunityeditions.wordpress.com
    Linux Basics: https://linuxbasicssite.wordpress.com

  • Thank you! It works! I’ll mark this as solved:grinning:.

    And thank you once again for the help. I’ve been trying to get this to work for awhile now…

    Keep trying, never give up. In the end, you will find that it was all worth it

    Community ISO: https://antergoscommunityeditions.wordpress.com
    Linux Basics: https://linuxbasicssite.wordpress.com

bash3 updating17 Posts 4Views 109
Log in to reply