Ubuntu Update Script

A few years ago I created this cheesy little script to perform a full update on a Ubuntu system and has the capability of upgrading a system to the next full release available. Currently there are about 200+ system running this little bad boy on a weekly basis to keep stuff up to date. It’s super simple and not full proof but it was created on a whim and has served me well. I am posting it because hopefully someone will find it useful.

Please understand what you are doing because this script can inadvertently break software compatibility.

#!/bin/bash

DATE=$(date +%F-%I.%M.%S)
LOG=/root/log/update.log
mkdir -p /root/log
echo -e "$DATE - Starting auto update" >> $LOG

system_update () {
    apt-get update;
    apt-get upgrade -y;
    apt-get dist-upgrade -y;
    apt-get autoremove -y;
    apt-get autoclean;
    apt-get clean;
}

system_upgrade () {
    apt-get install ubuntu-release-upgrader-core
    do-release-upgrade
}

install_ntpdate () {
    if ! [ -x "$(command -v ntpdate)" ]; then
    echo -e "CHECKING FOR NTPDATE"
    apt-get install -y ntpdate;
    fi
}

time_update () {
    echo -e "updating time"
    ntpdate -s time.nist.gov
}


system_update
install_ntpdate
time_update
#system_upgrade

DATE=$(date +%F-%I.%M.%S)
echo -e "$DATE - Completed auto update" >> $LOG
exit

Scroll to Top