From 19046926f1b86d9c739fe7187a98381362650e8f Mon Sep 17 00:00:00 2001 From: jgaunt Date: Tue, 5 Jan 2021 12:14:14 -0500 Subject: [PATCH] updated already configured check and updated hostname command --- zabbix_agent.sh | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/zabbix_agent.sh b/zabbix_agent.sh index 1cbde73..7fcfdf4 100644 --- a/zabbix_agent.sh +++ b/zabbix_agent.sh @@ -85,12 +85,16 @@ fi cheeck before running this as it adds lines to keep comments -if [ $(grep -c Hostname=Zabbix /etc/zabbix/zabbix_agentd.conf) -eq 1 ]; then +if [ $(grep -c Server=127.0.0.1 /etc/zabbix/zabbix_agentd.conf) -eq 1 ]; then # ask for the hostname read -e -p "Enter Hostname: " -i "$(cat /etc/hostname)" hostname - # configure the hostname - sed --in-place 's/^Hostname=Zabbix\ server/Hostname='${hostname}'/' /etc/zabbix/zabbix_agentd.conf + # configure the hostname, check for older config and newer config + if [ $(grep -c Hostname=Zabbix /etc/zabbix/zabbix_agentd.conf) -eq 1 ]; then + sed --in-place 's/^Hostname=Zabbix\ server/Hostname='${hostname}'/' /etc/zabbix/zabbix_agentd.conf + else + sed --in-place $'s/^# Hostname=/# Hostname=\\\nHostname='${hostname}'/' /etc/zabbix/zabbix_agentd.conf + fi # configure the zabbix server sed --in-place 's/^Server=127.0.0.1/Server='${ZABBIX_SERVER}'/' /etc/zabbix/zabbix_agentd.conf # configure the zabbix server