Shell 用于解析 JTL/XML 文件以了解特定节点是否具有值的脚本
Shell Script to parse JTL/XML file to know if a specific node has a value
我有一个 JTL 文件,我需要对其进行解析以了解名为 的节点是否具有 true
作为其值。
我需要调用一个脚本文件,它应该能够在 if
条件下做出此决定,我需要根据该条件执行其他操作。如何实现 JTL/XML 的解析以了解 failure-true
是否存在?
此 JTL 文件中有很多 节点。
编辑:我可能构建错了。我正在尝试的只是一个 shell 脚本,如果它解析的 JTL 文件有一个值为 true
.
的节点 ,它将执行特定操作
<?xml version="1.0" encoding="UTF-8"?>
<testResults version="1.2">
<httpSample t="153" lt="152" ts="1434726402307" s="true" lb="xyz" dt="text" by="14"/>
<httpSample t="169" lt="169" ts="1434726402603" s="true" lb="asdasd" dt="text" by="471">
<assertionResult>
<name>Response Assertion</name>
<failure>false</failure>
<error>false</error>
</assertionResult>
</httpSample>
.
.
.
如此继续
grep
用于 .jtl 文件中的 <failure>true</failure>
。
if grep -q <failure>true</failure> file.jtl; then
echo found
else
echo not found
fi
如果您不关心哪个节点具有值,那么可以使用 grep 来完成。
if grep -q '<failure>true<\/failure>' jmeter-test.jtl ;then
echo "FAILURE"
fi
执行此操作的安全方法是使用 XML 感知工具:
failure=$(xmlstarlet sel -t -m '//assertionResult/failure' -v . -n <jmeter-test.jtl)
if [[ $failure = true ]]; then
echo "failed"
else
echo "success"
fi
与朴素的 grep
方法不同,它只识别位于正确位置的 failure
-- 在 assertionResult
下,而不是在评论中,而不是在从程序输出等
我有一个 JTL 文件,我需要对其进行解析以了解名为 true
作为其值。
我需要调用一个脚本文件,它应该能够在 if
条件下做出此决定,我需要根据该条件执行其他操作。如何实现 JTL/XML 的解析以了解 failure-true
是否存在?
此 JTL 文件中有很多
编辑:我可能构建错了。我正在尝试的只是一个 shell 脚本,如果它解析的 JTL 文件有一个值为 true
.
<?xml version="1.0" encoding="UTF-8"?>
<testResults version="1.2">
<httpSample t="153" lt="152" ts="1434726402307" s="true" lb="xyz" dt="text" by="14"/>
<httpSample t="169" lt="169" ts="1434726402603" s="true" lb="asdasd" dt="text" by="471">
<assertionResult>
<name>Response Assertion</name>
<failure>false</failure>
<error>false</error>
</assertionResult>
</httpSample>
.
.
.
如此继续
grep
用于 .jtl 文件中的 <failure>true</failure>
。
if grep -q <failure>true</failure> file.jtl; then
echo found
else
echo not found
fi
如果您不关心哪个节点具有值,那么可以使用 grep 来完成。
if grep -q '<failure>true<\/failure>' jmeter-test.jtl ;then
echo "FAILURE"
fi
执行此操作的安全方法是使用 XML 感知工具:
failure=$(xmlstarlet sel -t -m '//assertionResult/failure' -v . -n <jmeter-test.jtl)
if [[ $failure = true ]]; then
echo "failed"
else
echo "success"
fi
与朴素的 grep
方法不同,它只识别位于正确位置的 failure
-- 在 assertionResult
下,而不是在评论中,而不是在从程序输出等