1. Log into the VirtualBox VM
2. Create a new file, updateVM.sh, for the bash script below, using the commands:
2.1 Sudo nano /home/adminuser/updateVM.sh
2.2 Copy the contents of the script into the file:
#!/bin/bash
# Script to be run within the EDSCLS VM
# Helps the updated VM
echo "Get list of updates needed"
currentDate=$(date +%F)
sudo apt-get update -y | tee update_log_$currentDate.txt
echo "Get list of upgrades needed"
sudo apt-get upgrade -y | tee -a update_log_$currentDate.txt
echo "Update Ubuntu server -- distribution upgrade"
sudo apt-get dist-upgrade -y | tee -a update_log_$currentDate.txt
echo "Remove any old versions of items that are no longer needed"
sudo apt autoremove --purge | tee -a update_log_$currentDate.txt
|
2.3 Save the file
3. Grant execute permissions to the script using the command:
Chmod 700 updateVM.sh
4. Run the bash script by using the command, ./updateVM.sh, in the Terminal window
4.1 All updates and upgrades save the output to a log file, named based on the current date: update_log_20220430.txt
4.2 Review the log files to ensure the updates were run successfully.
5. Patching is complete.
6. Open Chromium and navigate to localhost to test the site and confirm everything is working as expected.
7. Reboot the Virtual Machine to ensure all updates are properly processed
8. OPTIONAL: If desired, the logs can be cleared out for a clean start with your newly updated version. If you wish to clear the log files:
8.1 Reopen a Terminal window
8.2 Navigate to the log folder:
cd /var/log
8.3 Clear the logs using the below bash script, using the commands:
8.3.1 Sudo nano /home/adminuser/clearLogs.sh
8.3.2 Copy the contents of the script into the file:
#!/bin/bash
echo "Clear logs"
cd /var/log
sudo rm -rf *.gz
sudo rm -rf *.log.1
sudo rm -rf */*.gz
sudo rm -rf */*.log.1
echo "Logs cleared"
|
8.3.3 Save the file
8.3.4 Grant execute permissions to the script using the command:
Chmod 700 clearLogs.sh
8.3.5. Run the bash script by using the command, ./clearLogs.sh, in the Terminal window
If the upgrades listed above did not work properly, the snapshot taken above in the “Backup Existing Virtual Machine (VM)” section may be restored, to revert the VM back to the previous working state.
1. Shutdown the VM, so it is Powered Off
2. Within VirtualBox, on the left navigation, select the menu icon next to the VM and select “Snapshots”
3. Find the name for the snapshot that you would like to restore and click on the name to select the snapshot and see the Name and Description.
4. Click the Restore button in the top menu.
5. VirtualBox will prompt you that you are going to roll back the current state. You can choose to create another snapshot of the current machine state by checking the box.
6. Click “Restore” to roll back the current state to the snapshot that was created.