Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modified the code (Reduced the code lines) #13

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions remote_backup_script/automatically_update_system_v2.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/bash

# Updating systems

function update_system() {
if [[ -f /etc/redhat-release ]]; then

if ! yum update -y && yum clean all; then
echo "Error: Failed to update the system."
return 1
else
echo "Ubuntu/Debian system update complete."
return 0
fi

elif [[ -f /etc/lsb-release ]]; then

if ! apt-get update -y && apt-get upgrade -y && apt-get dist-upgrade -y && apt-get autoremove -y && apt-get autoclean -y; then
echo "Error: Failed to update the system."
return 1
else
echo "CentOS/RHEL/Fedora system update complete."
return 0
fi

else

if [ -f /etc/os-release ]; then
. /etc/os-release
else
echo "Error: Unable to detect distribution type."
return 1
fi
fi
}

# Call the update_system function
update_system