Ubuntu auto script

So I was pretty tired of updating every single server I was messing around with for experimental purpose so I decided to create an auto scripting for the usual ‘apt update && apt upgrade’ command

Go to your server

ssh root@example.com

Go to the folder where Cron exists. Cron is a time-based scheduler that allows daily, weekly, monthly and custom scripting. https://help.ubuntu.com/community/AutoWeeklyUpdateHowTo

cd /etc/cron.weekly

If I wanted it to run the updates and upgrades on a daily basis, it would be ‘cron.daily’. So in the directory where you wish to schedule your auto script, create a file using any editor of your choice (vim for me)

vim auto_update

In the file add

apt update && apt upgrade -y 
apt autoclean 
apt autoremove

A note though that upgrade might sometimes cause stuff to break, so a heads up here.

‘apt autoclean‘ → cleans obsolete packages,
‘apt autoremove‘ → removes orphaned packages which are not longer needed from the system

Now, to make the file executable in order for cron to be able to run it. In the directory where the script is, run,

chmod 755 auto_update 

Some other stuff you can do is to find files in example directory with size >+30GB and execute remove

find ~/example -type f -size +30000M -exec rm {} \;﻿

Leave a comment
