Announcement

Collapse
No announcement yet.

Script to check repositories for updates

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Script to check repositories for updates

    I wrote this bash script to automatically check for updates in the repositories.

    Notes:
    1. It can be used from the console or set to run periodically as a cronjob (I have it running every 6 hours)
    2. It does not perform any upgrades, just reports available updates, so it's 'safe' to use unattended.
    3. The reason it uses logs as well as standard output is because I wanted to make it possible to easily monitor updates with apps like SuperKaramba. (you can easily 'grep' the logs in your Karamba themes for the information you need).

    Any questions comments and/or improvement suggestions are welcome.

    Code:
    #!/bin/bash
    # Function: Script checks for available updates in sources.log repositories
    # Output: Screen and two logfiles
    # Usage: 1. From the console with sudo
    #	 2. Automatic as a cronjob, logs can be monitored with SuperKaramba, for example	
    
    #Check if root
    ROOT_UID=0
    if [ "$UID" -ne "$ROOT_UID" ]
      then
        echo "You need root priviledges to run this script."
        exit 67
    fi
    
    #Check repositories and print log to file with possible error messages
    echo "Updating package lists..."
    apt-get -ds update > /var/log/repo_get.log 2>&1
    
    # Error check to see if package lists were succesfully loaded (and that apt is not locked by other package managers like synaptic)
    ERRORS=`grep -c 'E:' /var/log/repo_get.log`
    if [ "$ERRORS" == 0 ]
       then
         grep -i ')' /var/log/repo_get.log
         echo
       else
         grep 'E:' /var/log/repo_get.log
         echo "Errors while fetching updates...exiting program"
         exit 1 #Exit on errors to avoid writing an empty update list
    fi
    
    #Writing and sorting available updates
    apt-get -yus upgrade > /var/log/repo_update.log
    grep 'Conf ' /var/log/repo_update.log | cut -d ' ' -f2 | sort
    
    echo -e '\033[1;32m'
    grep -i ',' /var/log/repo_update.log | cut -d ',' -f1
    echo -e '\033[0m'
    echo "Done...exiting program"
    exit 0

    #2
    Re: Script to check repositories for updates

    I have a KDE version of this. It displays an icon inthe tray and checks every 2 hours for updates. When updates are available the icon changes and you have the option to upgrade your system.

    You can try it out http://www.solar1.net/index.php?ind=...ry_view&iden=1.

    Comment

    Working...
    X