21 lines
634 B
Bash
21 lines
634 B
Bash
#!/bin/bash
|
|
|
|
ip_address="127.0.0.1"
|
|
host_name="console.tiab.ing.net"
|
|
|
|
# find existing instances in the host file and save the line numbers
|
|
matches_in_hosts="$(grep -n $host_name /etc/hosts | cut -f1 -d:)"
|
|
host_entry="${ip_address} ${host_name}"
|
|
|
|
if [ ! -z "$matches_in_hosts" ]
|
|
then
|
|
echo "Aktualisieren des vorhandenen Hosteintrags."
|
|
# Prüfen auf Übereinstimmungen
|
|
while read -r line_number; do
|
|
# Ersetzen Sie den Text jeder Zeile durch den gewünschten Hosteintrag
|
|
sudo sed -i '' "${line_number}s/.*/${host_entry} /" /etc/hosts
|
|
done <<< "$matches_in_hosts"
|
|
else
|
|
|
|
echo "$host_entry" | sudo tee -a /etc/hosts > /dev/null
|
|
fi |