I use the following script to automatically update my Ubuntu box.
I don’t recommend using this on your production servers!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
#!/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.