Thursday, 25 November 2021

Bash script – Update, upgrade and clean linux

 

Basic bash script – Beginner friendly

Go ahead and watch my YouTube video on this, I talk through the code and explain what it is essentially doing. 


 

Why and when would I use this bash script?

Why?

The commands within this bash script are essential commands to the linux system. It is important to keep your system up to date, doing so will make your system more secure and run more efficiently.

When?

This depends on how much you use your linux machine. You could run this bash script once a day, or everytime you log in. It is completely up to you. I would recommend running this atleast once a week, more often if you can.

Where do I write my bash script?

I am going to make some enemies here. I use gedit. YES! I use a text editor outside of my terminal. I am ‘that’ guy. You can use whatever text editer you want. No judgements here.

If you have not already got gedit installed. Run the following command before you begin.

sudo apt-get install gedit

Great now here is the script.

#!/bin/bash/ 

echo 

echo -e "\e[1;32m Step 1: Updating packages \e[0m"
sudo apt-get update

echo

echo -e "\e[1;32m Step 2: Upgrading packages \e[0m" 
sudo apt-get upgrade -y
sudo apt-get dist upgrade -y 
sudo apt-get update

echo 

echo -e "\e[1;32m Step 3: Cleaning up \e[0m"
sudo apt-get clean
sudo apt-get autoclean
sudo apt-get autoremove

exit 

Output

Beautiful isn’t it?

Could be better…

So the output of this script is good, but technically speaking, we are missing a few major pieces here.

Firstly – What happens if the script fails? We could have a red text that comes up telling us how or why the script failed to run.

Secondly – We are not logging anything here. We can add this to system logs or our own personal log file. This would become more important if you were tracking when the linux system was last updated for audit purposes.

Why don’t you try and make this script better?

Build on it, edit it, use it. Then share this with me, I would be really interested in seeing what changes you can come up with for this.

No comments:

Post a Comment

CISA Exam Guide

  CISA Exam guide  If you want to watch my video talking about the CISA exam and sharing some tips check out my YouTube video below.   What ...