28 lines
876 B
Bash
28 lines
876 B
Bash
#!/bin/bash
|
|
|
|
CONFIG_FILE="/etc/zabbix/zabbix_agent2.conf"
|
|
SEARCH_STRING="10.44.0.5"
|
|
REPLACE_STRING="zabbix.moeny.internal"
|
|
|
|
# Check if the configuration file exists using sudo
|
|
if ! sudo test -f "$CONFIG_FILE"; then
|
|
echo "Error: File $CONFIG_FILE not found."
|
|
exit 1
|
|
fi
|
|
|
|
# Check if the search string exists in the file using sudo
|
|
if sudo grep -q -F "$SEARCH_STRING" "$CONFIG_FILE"; then
|
|
# Escape dots in the search string for sed
|
|
ESCAPED_SEARCH_STRING=$(echo "$SEARCH_STRING" | sed 's/\./\\./g')
|
|
|
|
# Replace the string in place using sudo without creating a backup
|
|
sudo sed -i "s/$ESCAPED_SEARCH_STRING/$REPLACE_STRING/g" "$CONFIG_FILE"
|
|
if [ $? -ne 0 ]; then
|
|
echo "Error: Failed to replace string."
|
|
exit 1
|
|
fi
|
|
|
|
echo "Replacement done."
|
|
else
|
|
echo "No replacement needed. The string '$SEARCH_STRING' was not found."
|
|
fi |