想要通过bash shell脚本编辑XML文件。 我被困在寻找解决方案 - 请分享您的建议,如果这可以通过bash shell脚本解决。从bash shell编辑XML文件
输入文件(将存储在服务器):
<?xml version="1.0" encoding="UTF-8"?>
<properties>
\t <directories installDir="/fs0/">
\t \t <directoriesInstance id="sharedDir" path=""/>
\t \t <directoriesInstance id="loaderInput" path="/fs0/share/iad/input"/>
\t \t <directoriesInstance id="loaderProcessing" path="/fs0/share/iad/processing"/>
\t \t <directoriesInstance id="loaderError" path="/fs0/share/iad/error"/>
\t \t <directoriesInstance id="loaderCompleted" path="/fs0/share/iad/completed"/>
\t </directories>
<applicationServerInstance id="app" serviceName="App Server" rmiPort="15001" jvmParameters="-Xmx3072m -Xms512m -XX:-UseGCOverheadLimit -XX:MaxPermSize=196m -Dsun.lang.ClassLoader.allowArraySyntax=true -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/fs0/clarity1/clarity/logs -Xloggc:/fs0/clarity1/clarity/logs/app_gc.log -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:+PrintHeapAtGC -Dcustom.properties=/fs0/share/custom.properties" maxThreads="1000" programParameters="" distributed="false" runJobScheduler="false" useSSO="true" maxConcurrentJobs="10" runProcessEngine="false" messageTimeToLive="120" messageReceiverInterval="5" exceptionRunInterval="normal" maxXmlNodesLimit="150000"/>
<applicationServer>
\t \t <applicationServerInstance id="app" serviceName=" App Server" rmiPort="15001" jvmParameters="-Xmx3072m -Xms512m -XX:-UseGCOverheadLimit -XX:MaxPermSize=196m -Dsun.lang.ClassLoader.allowArraySyntax=true -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/fs0/clarity1/clarity/logs -Xloggc:/fs0/clarity1/clarity/logs/app_gc.log -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:+PrintHeapAtGC -Dcustom.properties=/fs0/clarity1/share/custom.properties" maxThreads="1000" programParameters="" distributed="false" runJobScheduler="false" useSSO="true" maxConcurrentJobs="10" runProcessEngine="false" messageTimeToLive="120" messageReceiverInterval="5" exceptionRunInterval="normal" maxXmlNodesLimit="150000"/>
\t </applicationServer>
</properties>
在上面的代码中,我想寻找applicationServerInstance标签,看看它是否有Dcustom.properties =/FS0 /清晰度1 /共享/ custom.properties jvmproperties标记 - 如果它不存在我想添加到文件并保存文件。 所有应该在bash shell脚本中。
我想-Dcustom.properties =/FS0 /股/ custom.properties值添加到jvmParameters属性在applicationServerInstance标签,如果不存在的话。在上面的例子中它有这个值,但是如果它不存在,我会添加这个-Dcustom.properties =/fs0/share/custom.properties值。
例如说我应该-Dcustom.properties =/FS0 /共享/ custom.properties值添加到jvmParameters属性在applicationServerInstance标签到下面片段。
<applicationServerInstance id="app" serviceName=" App Server" rmiPort="15001" jvmParameters="-Xmx3072m -Xms512m -XX:-UseGCOverheadLimit -XX:MaxPermSize=196m -Dsun.lang.ClassLoader.allowArraySyntax=true -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/fs0/clarity1/clarity/logs -Xloggc:/fs0/clarity1/clarity/logs/app_gc.log -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:+PrintHeapAtGC " maxThreads="1000" programParameters="" distributed="false" runJobScheduler="false" useSSO="true" maxConcurrentJobs="10" runProcessEngine="false" messageTimeToLive="120" messageReceiverInterval="5" exceptionRunInterval="normal" maxXmlNodesLimit="150000"/>
没有'jvmproperties' *标记*,但该值包含在'jvmParameters' *属性*中。你想添加值,还是替换现有的'custom.properties'? – choroba
我想为** jvmParameters **属性添加** - Dcustom.properties =/fs0/share/custom.properties **值在** applicationServerInstance **标记中(如果它不存在)。在上面的例子中,它有这个值,但是如果它不存在,我会添加这个** - Dcustom.properties =/fs0/share/custom.properties **值。 – Naga
您可以查看用于命令行XML处理的xmlstarlet。 –