Skip to content

Instantly share code, notes, and snippets.

@charles-dyfis-net
Last active November 2, 2015 19:34
Show Gist options
  • Save charles-dyfis-net/5bfee9f721ec75ebee3e to your computer and use it in GitHub Desktop.
Save charles-dyfis-net/5bfee9f721ec75ebee3e to your computer and use it in GitHub Desktop.
creating config files for nagios
#!/bin/bash
while IFS=, read -r host ip cont _ <&3; do
parent=${ip%.*}.1
TMPL=HOST-TEST.tmpl
FILE=$host.cfg
awk \
-v HOST="$host" \
-v CONT="$cont" \
-v PARENT="$parent" \
-v IP="$ip" \
'{
sub("HOSTNAME", HOST, $0);
sub("CONTACTGROUP", CONT, $0);
sub("PARENT", PARENT, $0);
sub("IPADDR", IP, $0);
print $0;
}' <"$TMPL" >"$FILE"
done 3< servers.csv
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment