An example:
Code: Select all
#!/bin/bash
awk 'BEGIN { print "host,template" }
/^define host \{/{
while ( $1 != "}" )
{
getline
if ( $1 == "host_name" )
{
HN=$NF
}
if ( index($1,"use") > 0 )
{
i=3;
template=$2;
while ( i <= NF )
{
template=template "," $i
i=i+1;
}
}
}
print HN "," "\""template"\""
HN="";
template="";
}' /usr/local/nagios/etc/hosts/*What I am wondering is if I am reinventing the wheel here. Has anybody already done this? Is there a way to get at this data by some mechanism that XI already has?