在上面的片段中,我想搜索应用服务器实例标签,看看它在jvmproperties标签中是否有Dcustom.properties=/fs0/clarity1/share/custom.properties - 如果它不存在,我想添加到文件中并保存该文件。 所有这些都应该在bash shell脚本中进行。

我想补充的是 -Dcustom.properties=/fs0/share/custom.properties 值为 ǞǞǞǞ 属性 在 应用服务器实例 标签,如果它不存在。在上面的例子中,它有这样的值,但如果它不存在,我想添加以下内容 -Dcustom.properties=/fs0/share/custom.properties 价值。

例如,我应该添加 -Dcustom.properties=/fs0/share/custom.properties 值为 ǞǞǞǞ 属性 在 应用服务器实例 标签到下面的片段。

<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"/>
5 个评论
There's no jvmproperties 标签 ,但该值包含在 jvmParameters 中。 归属 .你是想增加价值,还是替换现有的 custom.properties
Naga
我想补充的是 -Dcustom.properties=/fs0/share/custom.properties 值为 ǞǞǞǞ 属性 在 应用服务器实例 标签,如果它不存在。在上面的例子中,它有这样的值,但如果它不存在,我想添加以下内容 -Dcustom.properties=/fs0/share/custom.properties 价值。
你可以看看xmlstarlet的命令行XML处理。
但如果 custom.properties 存在,但数值不同呢?
Naga
在-Dcustom.propertie中不可能有一个不同的值。
linux
bash
shell
Naga
Naga
发布于 2016-10-20
2 个回答
selvam
selvam
发布于 2016-10-27
0 人赞同

在你的XML文件中,第一个applicationServerInstance标签有jvmParameters的-Dcustom.properties=/fs0/share/custom.properties值。但在第二个applicationServerInstance标签中,jvmParameter有-Dcustom.properties=/fs0/clarity1/share/custom.properties值,而不是-Dcustom.properties=/fs0/share/custom.properties。在这种情况下,我的代码片段增加了一个Dcustom.properties值。

所以第二个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 -Dcustom.properties=/fs0/clarity1/share/custom.properties -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"/>

Bash脚本。

#!/usr/bin/env bash
file_name="/home/selvam/Scripts/test.xml"
for i in $(grep -nE "<applicationServerInstance.*jvmParameters" $file_name | cut -d ':' -f1)
    jvm_parameters=$(head -$i $file_name | tail -1 | awk -F '"' '{ for (c=1; c<=NF; c++) if ($c ~ /jvmParameters/) print $(c+1)}')
    echo $jvm_parameters | grep -q 'Dcustom.properties=/fs0/share/custom.properties'
    if ([ $? -ne 0 ]) then
        jvm_new_parameters=$(echo $jvm_parameters -Dcustom.properties=/fs0/share/custom.properties)
        sed -i "${i}s%jvmParameters=\"$jvm_parameters\"%jvmParameters=\"$jvm_new_parameters\"%" $file_name
    
Ovidiu Albu
Ovidiu Albu
发布于 2016-10-27
0 人赞同