/ Published in: Bash
Here's a quick one-off trick for sed editing conf files on remote hosts. I will
post the core sed command first, showing the crazy quoting, then a for loop demonstrating how one might tackle multiple hosts. Took me a few tries to get the quoting so thought I'd save others the trouble.
In this example I had to change the homepage variable in a remote conf file.
* The URL needs single quotes in the conf file. '\'' does the trick.
* The End of Line metacharacter '$' needs to be escaped for bash. Like so, \$.
* Finally, note that the sed expression is wrapped in single quotes while the whole command is wrapped with double quotes. I tried other combos -- if you know why this is so, do tell.
post the core sed command first, showing the crazy quoting, then a for loop demonstrating how one might tackle multiple hosts. Took me a few tries to get the quoting so thought I'd save others the trouble.
In this example I had to change the homepage variable in a remote conf file.
* The URL needs single quotes in the conf file. '\'' does the trick.
* The End of Line metacharacter '$' needs to be escaped for bash. Like so, \$.
* Finally, note that the sed expression is wrapped in single quotes while the whole command is wrapped with double quotes. I tried other combos -- if you know why this is so, do tell.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
ssh root@$host "sed -i 's#\(CONF_VAR=\).*\$#\1'\''http://fakesite.org/splash'\''#' /etc/prog/prog-conf.conf" for host in 10.10.23.{11..33} do ssh root@$host "sed -i 's#\(CONF_VAR=\).*\$#\1'\''http://fakesite.org/splash'\''#' /etc/prog/prog-conf.conf" done