Skip to content

Commit 19623b8

Browse files
Update hostCorrect.sh
Updated to account for missing "serverName" value in local "server.conf"
1 parent da13af3 commit 19623b8

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

bin/hostCorrect.sh

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ INPUTS_FILE="$SPLUNK_HOME/etc/system/local/inputs.conf"
44
SERVER_FILE="$SPLUNK_HOME/etc/system/local/server.conf"
55
RESTART_INPUT_CHECK="$SPLUNK_HOME/etc/restartinput.txt"
66
RESTART_SERVER_CHECK="$SPLUNK_HOME/etc/restartserver.txt"
7-
CURRENT_SERVER=$(cat "$SERVER_FILE" | grep "serverName =" | awk '{printf $3}')
87

98
### Check for the existence of the inputs file and create if it doesn't exist
109
if [ -f "$INPUTS_FILE" ]; then
@@ -17,7 +16,17 @@ else
1716
CURRENT_HOST=$(cat "$INPUTS_FILE" | grep "host =" | awk '{printf $3}')
1817
fi
1918

20-
### Compare those values and correct if necessary
19+
### Check for the existence of a serverName value and insert one if one isn't configured
20+
CURRENT_SERVER=$(cat "$SERVER_FILE" | grep "serverName =" | awk '{printf $3}')
21+
if [ -z "CURRENT_SERVER" ]; then
22+
echo "$(date +"%Y-%m-%d %H:%M:%S.%3N") ${HOSTNAME}: There is no serverName value configured. Inserting one..."
23+
echo "
24+
[general]
25+
host = IntentionallyWrong" >> "$SERVER_FILE"
26+
CURRENT_SERVER=$(cat "$SERVER_FILE" | grep "serverName =" | awk '{printf $3}')
27+
fi
28+
29+
### Check the current values of the configured files and correct if necessary
2130
if [ "$CURRENT_HOST" = "$HOSTNAME" ]; then
2231
echo "$(date +"%Y-%m-%d %H:%M:%S.%3N") ${HOSTNAME}: Currently configured host name: $CURRENT_HOST. No correction necessary..."
2332
else

0 commit comments

Comments
 (0)