I want the below script to omit every chunk of data that contains a specific hostname.
here's the scenario. i have a configuration file that contains the configuration of several hosts. a sample of this configuration file is this:
define host {
address 10.70.40.40
host_name relay-nasty-01.net
use generic-host
}
define host {
address 10.70.40.42
host_name relay-nasty-02.net
use generic-host
}
define host {
address 10.70.40.43
host_name relay-nasty-03.net
use generic-host
}
The above is the configuration for Three hosts: relay-nasty-01.net, relay-nasty-02.net, relay-nasty-03.net.
now, this configuration data is quite huge, since it contains information for several hosts.
now, i want to scan this configuration file against a list of host names. and if any of the hostname in this list is found in the configuration file, i want information about that host name to be omitted. I want a new configuration file created without the configuration for that host name(s).
so for example, if relay-nasty-02.net was in the list of hostnames i want to remove from the configuration file, i want a script that will scan the configuration and output EVERYTHING ELSE BUT the configuration for relay-nasty-02.net.
below is a script i was working on. but i dont know how to modify it to do what i specified above.
awk 'BEGIN {
while((getline < "/tmp/host_list.txt")>0)
S[$0]
FS="\n"; RS="}\n"; ORS="}\n";
}
/define host/ {
for(X in D) delete D[X];
for(N=2; N<=NF; N++)
{
split($N, A, " ");
D[A[1]]=A[2];
}
if (D["host_name"] in S)
printf("%s -------- %s -------- %s\n", D["host_name"]" " " ", D["address"], D["_secondary_address"])
}' /tmp/hosts.conf
so basically, i would like to modify this script to make it so, when i scan it against the configuration file, it will omit the configuration setup of the host(s) in the list i give it.
so in my example, if i run this script, it should only output the below, because relay-nasty-02.net was in the list of hosts i gave it.
define host {
address 10.70.40.40
host_name relay-nasty-01.net
use generic-host
}
define host {
address 10.70.40.43
host_name relay-nasty-03.net
use generic-host
}
OS: linux/sun
shell: bash