From f0be11c8f0490afd3be22a6a487cd0a1c1f8c0d4 Mon Sep 17 00:00:00 2001 From: Laurie Barker Date: Tue, 4 Jan 2022 12:51:44 +0000 Subject: [PATCH] NodeQuery Agent Removal Script Uninstall script for removal of cron job, user and agent code. Response to service no longer being active. Based on install agent and designed to help administrators remove service from active servers. --- nq-uninstall.sh | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 nq-uninstall.sh diff --git a/nq-uninstall.sh b/nq-uninstall.sh new file mode 100644 index 0000000..0313d53 --- /dev/null +++ b/nq-uninstall.sh @@ -0,0 +1,48 @@ +#!/bin/bash +# +# NodeQuery Agent Removal Script +# +# Set environment +PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin + +# Prepare output +echo -e "|\n| NodeQuery Uninstaller\n| ===================\n|" + +# Root required +if [ $(id -u) != "0" ]; +then + echo -e "| Error: You need to be root to uninstall the NodeQuery agent\n|" + exit 1 +fi + +# Attempt to delete previous agent +if [ -f /etc/nodequery/nq-agent.sh ] +then + + # Remove cron entry and user + if id -u nodequery >/dev/null 2>&1 + then + # Show Feedback + echo -e "|\n| nodequery user [FOUND]\n|" + + (crontab -u nodequery -l | grep -v "/etc/nodequery/nq-agent.sh") | crontab -u nodequery - && userdel nodequery + + # Show Feedback + echo -e "|\n| nodequery user & cron [DELETED]\n|" + fi + + # Show Feedback + echo -e "|\n| /etc/nodequery/nq-agent.sh [FOUND]\n|" + + # Remove agent dir + rm -Rf /etc/nodequery + + # Show Feedback + echo -e "|\n| /etc/nodequery [DELETED]\n|" + +else + + # Show Feedback + echo -e "|\n| /etc/nodequery/nq-agent.sh not found\n|" + +fi