Auto update for Debian/Ubuntu

I use the following script to automatically update my Ubuntu box.
I don’t recommend using this on your production servers!

#!/bin/bash
 
#################################################
##                                             ##
## auto-update.sh v1.0                         ##
## Use this script to set up automatic updates ##
## on your debian/ubuntu box.                  ##
##                                             ##
#################################################
 
## Creating /usr/bin/auto-update.sh file
sudo touch /usr/bin/auto-update.sh
sudo chmod 700 /usr/bin/auto-update.sh
sudo chown root:root /usr/bin/auto-update.sh
echo '#!/bin/bash' | sudo tee -a /usr/bin/auto-update.sh
echo 'touch /var/log/auto-update.log' | sudo tee -a /usr/bin/auto-update.sh
echo 'echo '------------------' >> /var/log/auto-update.log' | sudo tee -a /usr/bin/auto-update.sh
echo 'echo `date` >> /var/log/auto-update.log' | sudo tee -a /usr/bin/auto-update.sh
echo 'PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/X11R6/bin' | sudo tee -a /usr/bin/auto-update.sh
echo 'export PATH' | sudo tee -a /usr/bin/auto-update.sh
echo '/usr/bin/aptitude update >> /var/log/auto-update.log' | sudo tee -a /usr/bin/auto-update.sh
echo '/usr/bin/aptitude -y safe-upgrade >> /var/log/auto-update.log' | sudo tee -a /usr/bin/auto-update.sh
echo 'exit' | sudo tee -a /usr/bin/auto-update.sh
 
# Creating a cron job for root user (it will run /usr/bin/auto-update.sh every day at 14:30)
echo '30 14 * * * /usr/bin/auto-update.sh > /dev/null' > cron_file.txt && sudo crontab -u root cron_file.txt && rm -f cron_file.txt

Note that there are some dangers regarding automatic updates. You can read more about it here.

Leave a Comment


NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

This site uses Akismet to reduce spam. Learn how your comment data is processed.

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.

Close