Skip to content

Instantly share code, notes, and snippets.

@stefan736
Last active February 9, 2022 13:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stefan736/87a4a1d4f35b387f9901c20aa181fa29 to your computer and use it in GitHub Desktop.
Save stefan736/87a4a1d4f35b387f9901c20aa181fa29 to your computer and use it in GitHub Desktop.
Auto Update Linux Machine
#!/bin/bash
#
# Auto Updating Debian (means also Ubuntu) based Linux installations
#
# add to crontab ($ crontab -e)
# @reboot /home/username/update.sh >> /home/username/update.sh.log 2>&1
# 30 1 * * * /home/username/update.sh >> /home/username/update.sh.log 2>&1
#
# recognize wether we are currently inside an update process
update_transaction_file=~/update.sh.transaction
if [ ! -f $update_transaction_file ]; then
cat /home/username/update.sh.log >> /home/username/update.sh.log.archive
echo "" > /home/username/update.sh.log
fi
echo
echo "################### START $(date) #############"
touch $update_transaction_file
sudo DEBIAN_FRONTEND=noninteractive apt-get update -yq
sudo DEBIAN_FRONTEND=noninteractive apt-get dist-upgrade --auto-remove --purge -yq
if [ -f /var/run/reboot-required ]; then
echo "Reboot required!"
sudo rm /var/run/reboot-required
echo "################### END BEFORE REBOOT $(date) #############"
sudo reboot
exit 0
fi
# do additional things
rm $update_transaction_file
echo "################### END $(date) #############"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment