From 1a9b9aaf079b9a6fba1847e3f0bb09abfd9c74ce Mon Sep 17 00:00:00 2001 From: Ionel Andrei Cataon Date: Tue, 23 Dec 2025 14:22:30 +0200 Subject: [PATCH] updateno1 --- Bash_scripting/updates.sh | 3 +-- Bash_scripting/updates2.sh | 39 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 2 deletions(-) create mode 100755 Bash_scripting/updates2.sh diff --git a/Bash_scripting/updates.sh b/Bash_scripting/updates.sh index 9d6b535..d724787 100755 --- a/Bash_scripting/updates.sh +++ b/Bash_scripting/updates.sh @@ -24,5 +24,4 @@ then check_exit_status $? "apt dist-upgrade" echo "Update completed successfully!" -f - +fi \ No newline at end of file diff --git a/Bash_scripting/updates2.sh b/Bash_scripting/updates2.sh new file mode 100755 index 0000000..ff8307b --- /dev/null +++ b/Bash_scripting/updates2.sh @@ -0,0 +1,39 @@ +#!/bin/bash +release_file=/etc/os-release +logfile=/var/log/updater.log +errorlog=/var/log/updater_errors.log + +check_exit_status() { + local status=$? + local command_name=$1 + if [ $status -ne 0 ]; then + echo "$(date): An error occurred during $command_name (exit code: $status). Check $errorlog." | tee -a $logfile + exit 1 + fi +} + +echo "$(date): Starting update process..." >> $logfile + +if grep -q "Ubuntu" $release_file || grep -q "Debian" $release_file; then + apt update >> $logfile 2>> $errorlog + check_exit_status "apt update" + + apt dist-upgrade -y >> $logfile 2>> $errorlog + check_exit_status "apt dist-upgrade" + + apt autoremove -y >> $logfile 2>> $errorlog + check_exit_status "apt autoremove" + + apt autoclean >> $logfile 2>> $errorlog + check_exit_status "apt autoclean" + + echo "$(date): Update completed successfully!" | tee -a $logfile + + # Optional: Check if reboot needed + if [ -f /var/run/reboot-required ]; then + echo "$(date): Reboot required for updates to take effect." | tee -a $logfile + fi +else + echo "This system is not Ubuntu or Debian-based. Exiting." | tee -a $logfile + exit 0 +fi \ No newline at end of file