I need help to write bash script, one of its part has a task to insert text between such tokens - first occurring { and last closed ] The real thing as following
{ <-----here start
"pools" : [
{
"url" : "stratum+tcp://server:3333",
"user" : "User",
"pass" : "x"
},
{
"url" : "stratum+tcp://server1:3333",
"user" : "User",
"pass" : "x"
}
] <-----here end
My script has aim to insert pool config for multiple servers. Bellow last closed ] there are another settings which should stay untouched.
I found a solution it extracts text between defined tokens, expression as follows:
sed -n '/{/{:a;n;/]/b;p;ba}' input.txt
But my task bit complex. I need to replace remote host config
{
"pools" : [
{
"url" : "stratum+tcp://server:3333",
"user" : "User",
"pass" : "x"
},
{
"url" : "stratum+tcp://server1:3333",
"user" : "User",
"pass" : "x"
}
]
some settings
.......
another seetings
}
With new server settings
{
"pools" : [
{
"url" : "stratum+tcp://anotherserver:3333",
"user" : "User",
"pass" : "x"
},
{
"url" : "stratum+tcp://anotherserver1:3333",
"user" : "User",
"pass" : "x"
}
]
I can append/replace new config on remote host as following
echo '{
"pools" : [
{
"url" : "stratum+tcp://anotherserver:3333",
"user" : "User",
"pass" : "x"
},
{
"url" : "stratum+tcp://anotherserver1:3333",
"user" : "User",
"pass" : "x"
}
]'| ssh root@$HOST -p $PORT 'cat > /remotehost/config.conf'
But the problem is, I need to keep original settings on remote host below ] token and only replace server section.