Used Copilot to update my Ubuntu maintenance script. I did tweak it slightly though since I am running LTS.
#!/bin/bash
# Update apt package lists
echo "Updating apt package lists..."
sudo apt update
if [[ $? -ne 0 ]]; then
echo "Error updating apt package lists. Exiting."
exit 1
fi
# Upgrade apt packages
echo "Upgrading apt packages..."
sudo apt upgrade
if [[ $? -ne 0 ]]; then
echo "Error upgrading apt packages. Exiting."
exit 1
fi
# Clean up apt packages
echo "Cleaning up apt packages..."
sudo apt autoremove -y && sudo apt clean
if [[ $? -ne 0 ]]; then
echo "Error cleaning up apt packages. Exiting."
exit 1
fi
# Update snap packages
echo "Updating snap packages..."
sudo snap refresh
if [[ $? -ne 0 ]]; then
echo "Error updating snap packages. Exiting."
exit 1
fi
# Remove old snap revisions (and disabled snaps)
#echo "Removing old snap revisions..."
#sudo snap remove --purge $(snap list --all | awk '/disabled|revision/{print $1"="$3}')
#if [[ $? -ne 0 ]]; then
# echo "Error removing old snap revisions. Exiting."
# exit 1
#fi
# Update Maldet database
echo "Updating Maldet database..."
sudo maldet -u
if [[ $? -ne 0 ]]; then
echo "Error updating Maldet database. Exiting."
exit 1
fi
# Start Maldet scan of /home (recent changes, quiet mode)
echo "Starting Maldet scan of /home (recent changes)..."
sudo maldet -r -q /home
if [[ $? -ne 0 ]]; then
echo "Error running Maldet scan. Exiting."
exit 1
fi
# Display Maldet scan log location
SCAN_LOG=$(maldet --report list | tail -n 1 | awk '{print $NF}')
if [[ -n "$SCAN_LOG" ]]; then
echo "Maldet scan log located at: $SCAN_LOG"
else
echo "Could not retrieve Maldet scan log location."
fi
echo "All done!"
No comments:
Post a Comment