create_maxscale.awk (990B)
#!/bin/awk -f
BEGIN{
found = 0;
if(boundary == "") {boundary = 4;}
if(number == "") {number = 2;}
if(port == "") {port = 3313;}
if(address == "") {address="192.168.2.99";}
pat="\\[server"(boundary-1)"\\]";
pat2="";
repl="";
for(i=boundary-2; i<boundary; i++) {
pat2=pat2"server"i",";
}
pat2=substr(pat2, 1, length(pat2) - 1);
for(i=boundary; i<boundary+number; i++) {
repl=repl",server"i;
}
}
{
if($0 ~ pat2) {
sub(pat2, pat2""repl, $0);
print $0;
} else {
print $0;
}
if($0 ~ pat) {
found = 1;
}
if((found == 1) && ($0 ~ /protocol=MariaDBBackend/)) {
for(i = boundary; i < (boundary+number); i++) {
port++;
print "\n[server"i"]";
print "type=server";
print "address="address;
print "port="port;
print "protocol=MariaDBBackend\n";
}
found = 0;
next;
}
}
END{
}