Input: I have a filename called 'myseedips' with a set of Ip addresses in it in the below structure
10.204.99.15
10.204.99.12
10.204.99.41
These can be 'n' number of IP addressess line by line.
Output I have no idea on bash programming. But I have to write a bash script to create a JSON file in the below structure. These IP addresses has to be in a loop, so that the JSON will change/extend depending on the length of myseedips file.
"cassandra": {
"nodes": [
{"ip_address": "10.204.99.15","type": "seed"},
{"ip_address": "10.204.99.12","type": "seed"},
{"ip_address": "10.204.99.41","type": "seed"}]
},
Also need to add logic to add comma at the end of each node for all nodes except the last. Do not append comma if there is only one node.
Example: May be be something like the below code logic, but in bash programming.
j string
j = `"cassandra": {"nodes": [`
for i =0;i<len(ips);i++ {
j = j + `{"ip_address": "` + ips[i] + `","type": "seed"},`
}
j = j + `}]}`
Thanks Nissar Sheik