Preserving your Ubuntu system up to date and putting in important packages will be finished effectively utilizing a easy Bash script. This information will stroll you thru making a script that automates system updates, upgrades put in packages, and installs particular packages of your selection. You possibly can run the script manually or schedule it to execute routinely at a set time utilizing cron jobs.
Step-by-Step Information
Step 1: Create the Bash Script
Begin by creating a brand new script file, for instance, update_and_install.sh
. This script will deal with all the mandatory steps for updating your system.
Instance Script: update_and_install.sh
#!/bin/bash # Replace package deal listing echo "Updating package deal listing..." sudo apt replace # Improve put in packages echo "Upgrading put in packages..." sudo apt improve -y # Dist-upgrade to make sure the kernel and different essential packages are upgraded echo "Performing dist-upgrade..." sudo apt dist-upgrade -y # Take away pointless packages echo "Eradicating pointless packages..." sudo apt autoremove -y # Set up particular packages (exchange with those you want) # Instance: sudo apt set up -y package1 package2 echo "Putting in specified packages..." sudo apt set up -y <package1> <package2> # Cleanup any pointless recordsdata echo "Cleansing up..." sudo apt clear # Test if a reboot is required if [ -f /var/run/reboot-required ]; then echo "A reboot is required to finish the set up." else echo "No reboot is critical." fi echo "System replace and package deal set up accomplished."
Step 2: Customise the Script
- Change the placeholders: Within the part the place it says
sudo apt set up -y <package1> <package2>
, exchange<package1> <package2>
with the names of the packages you need to set up. For instance:
sudo apt set up -y git curl
If you happen to don’t have any particular packages to put in, you possibly can omit this half.
Step 3: Make the Script Executable
Earlier than you possibly can run the script, it’s essential to make it executable. To do that:
- Open a terminal.
- Navigate to the listing the place your script is saved.
- Run the next command:
chmod +x update_and_install.sh
Step 4: Run the Script
Now, you possibly can manually run the script to replace your system and set up packages. Within the terminal, run:
This can replace your package deal listing, improve put in packages, take away pointless ones, and set up the desired packages.
Step 5: Schedule the Script with Cron (Optionally available)
To automate the method, you possibly can schedule the script to run at a selected time utilizing cron
. Right here’s methods to set it as much as run, for instance, day by day at 2 AM.
- Open the cron desk for modifying:
- Add a line to schedule the script. For a day by day replace at 2 AM, add:
0 2 * * * /path/to/update_and_install.sh
Change /path/to/update_and_install.sh
with the precise path to your script.
- Save and exit. Now your system will routinely run the script on the specified time.
Conclusion
This easy Bash script is an effective way to make sure your Ubuntu system is at all times up-to-date and geared up with the mandatory packages. By operating it manually or automating it by means of cron jobs, it can save you time and maintain your system maintained with minimal effort.
Associated
Uncover extra from Patrick Domingues
Subscribe to get the most recent posts despatched to your e-mail.