问题
I asked Previously how to replace statement in xml file
<app-connector port="${APP_CONNECTOR_PORT}" address="192.168.0.254"
By
<app-connector port="${APP_CONNECTOR_PORT}" address="0.0.0.0"
Someone Helped me by giving a sed command which works in single host.
sed -i '/<app-connector port="${APP_CONNECTOR_PORT}" address="192.168.0.254"$/s/192.168.0.254/0.0.0.0/' file
So Now the question is to apply this to serveral hosts in text file:
192.168.0.1 192.168.0.2 192.168.0.3 192.168.0.4 192.168.0.5
I tried this and it doesn't works correctly:
for q in `cat listhosts`
do
ssh $q 'cd /opt/exercise5; find . -type f -name 'config.xml' -print -exec bash -c "sed -i '/<app-connector port="${APP_CONNECTOR_PORT}" address="192.168.0.254"$/s/192.168.0.254/0.0.0.0/' file" \;; exit'
done
a question asked also to do it with xmllint
Can you help me please,
Thank you
回答1:
There is no need to cd into the directory before executing find as you can use the path to the directory. You also need to use place holders when using find -exec and so:
ssh $q "find /opt/exercise5 -type f -name 'config.xml' -exec sed -i '/<app-connector port=\"${APP_CONNECTOR_PORT}\" address=\"192.168.0.254\"$/s/192.168.0.254/0.0.0.0/' '{}' \;"
来源:https://stackoverflow.com/questions/65810065/modify-an-xml-server-on-several-servers