From 71ee1e9f9e90e8a5c17a6749233dee03d7ae844b Mon Sep 17 00:00:00 2001 From: Ionel Andrei Cataon Date: Tue, 23 Dec 2025 13:53:53 +0200 Subject: [PATCH] new updates --- Bash_scripting/updates.sh | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100755 Bash_scripting/updates.sh diff --git a/Bash_scripting/updates.sh b/Bash_scripting/updates.sh new file mode 100755 index 0000000..9d6b535 --- /dev/null +++ b/Bash_scripting/updates.sh @@ -0,0 +1,28 @@ +#!/bin/bash +release_file=/etc/os-release +logfile=/var/log/updater.log +errorlog=/var/log/updater_errors.log + +check_exit_status() { + local status=$1 + local command_name=$2 + if [ $status -ne 0 ] + then + echo "An error occurred during $command_name, please check the $errorlog file." + exit 1 + fi +} + +if grep -q "Ubuntu" $release_file || grep -q "Debian" $release_file +then + # The host is Debian or Ubuntu + # Run the apt version of the command + sudo apt update 1>>$logfile 2>>$errorlog + check_exit_status $? "apt update" + + sudo apt dist-upgrade -y 1>>$logfile 2>>$errorlog + check_exit_status $? "apt dist-upgrade" + + echo "Update completed successfully!" +f +