From 74c4ff180ad68893697a8a71cf908455c5340845 Mon Sep 17 00:00:00 2001 From: Danny de Kooker Date: Wed, 6 Sep 2023 13:40:09 +0200 Subject: [PATCH] Finalized script and added synopsis --- Task_scripts/Linux - Schedule agent update.sh | 37 ++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/Task_scripts/Linux - Schedule agent update.sh b/Task_scripts/Linux - Schedule agent update.sh index ebf172d..38b8845 100644 --- a/Task_scripts/Linux - Schedule agent update.sh +++ b/Task_scripts/Linux - Schedule agent update.sh @@ -1,4 +1,33 @@ #!/bin/bash +# Usage: "Linux - Schedule agent update.sh" +# +# Description: +# This script is used from inside of Tactical RMM instances to schedule an update of a linux agent. +# The script will download the update script and schedule it to run after 2 minutes, +# this is done because the update script needs to stop and replace the agent files on the host. +# +# Options: +# n/a +# +# Author: D. de Kooker (info@dcomputers.nl) +# Sources: n/a + +#Check if at is installed in order to schedule the update script +check_at=$(which at 2> /dev/null) +if [[ $check_at == "" || $check_at =~ .*"no at".* ]]; then + echo "'at' could not be found. Trying to install automatically." + if [[ `which yum` ]]; then + yum -y install at + echo "'at' command installed successfully." + elif [[ `which apt` ]]; then + apt-get -y update + apt-get -y install at + echo "'at' command installed successfully." + else + echo "Failed to install 'at' command. Please install it manually." + fi + exit 1 +fi # GitHub script URL GITHUB_URL="https://gittea.dannydekooker.nl/Dcomputers/TacticalRMM_Scripts/raw/branch/main/Supporting_scripts/Linux%20-%20Update%20TRMM%20agent.sh" @@ -7,7 +36,7 @@ GITHUB_URL="https://gittea.dannydekooker.nl/Dcomputers/TacticalRMM_Scripts/raw/b DEST_DIR="/tmp" # Name of the script file -SCRIPT_FILE="trmm-agentupdate.sh" +SCRIPT_FILE="temp-trmm-agentupdate.sh" # Download the script from GitHub wget -O "$DEST_DIR/$SCRIPT_FILE" "$GITHUB_URL" @@ -18,6 +47,12 @@ if [ $? -eq 0 ]; then # Schedule the script to run after 2 minutes echo "bash $DEST_DIR/$SCRIPT_FILE update amd64" | at now + 2 minutes echo "Script scheduled to run after 2 minutes." + + # Schedule Cleanup of the update script + echo "rm -rf $DEST_DIR/$SCRIPT_FILE" | at now + 15 minutes + + exit 1 else echo "Failed to download the script from GitHub." + exit 0 fi \ No newline at end of file