Revision: 51367
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at September 22, 2011 04:41 by bubnoff
Initial Code
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
Initial URL
Initial Description
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.
Initial Title
Remote sed editing multiple hosts: How to quote
Initial Tags
Bash
Initial Language
Bash