Modify an xml server on several servers

♀尐吖头ヾ 提交于 2021-01-29 15:41:02

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!