我通过运行脚本获取IHS和JAVA的版本
/ihs_home/HTTPServer/bin/versionInfo.sh
它针对不同版本的 IBM HTTP Server 产品打印不同的输出。
输出的示例摘录如下:
.....
Installed Product
--------------------------------------------------------------------------------
Name IBM SDK, Java Technology Edition, Version 8
Version 8.0.3.0
ID JAVA8
Build Level pxa6480sr3ifix-20160615_01
Build Date 06/15/16
Architecture x86-64 (64 bit)
Installed Product
--------------------------------------------------------------------------------
Name IBM HTTP Server for WebSphere Application Server
Version 9.0.5.3
ID IHS
Build Level f5032008.04
Build Date 2/26/20
Package com.ibm.websphere.IHS.v90_9.0.5003.20200226_0941
Architecture x86-64 (64 bit)
Installed Features Core runtime
--------------------------------------------------------------------------------
.....
在上面的输出中,JDK 版本显示在 WEBSPHERE(IHS) 版本之前。
不幸的是,对于此 IBM 产品的不同版本,输出可能会发生变化,并且可能会在 WEBSPHERE(IHS) 版本之后显示 JDK 版本。
因此,
/ihs_home/HTTPServer/bin/versionInfo.sh | grep -v Directory | grep -v reporter | grep -i version
Output:
Version 8.0.3.0
Version 9.0.5.3
但是,我无法确定第一个版本是 WEBSPHERE(IHS) 还是 JDK。
我需要检查版本之前的行是否包含WebSphere
下面的版本条目是 websphere(ihs),否则它是 JDK 版本
--------------------------------------------------------------------------------
Name IBM HTTP Server for WebSphere Application Server
Version 9.0.5.3
如何使用脚本确定 websphere 和 JDK 版本versionInfo.sh
。
有人可以建议吗?
答案1
你的问题不清楚,但每当你的输入中有标签/名称到值对时,我发现最好首先创建这些配对的数组(tag2val[]
如下),然后你可以测试和/或打印你想要的任何内容喜欢,但你喜欢按照你喜欢的顺序,例如:
$ cat file | awk -v OFS='\t' '
{ tag=val=$0; sub(/[[:space:]].*/,"",tag); sub(/[^[:space:]]*[[:space:]]+/,"",val); tag2val[tag]=val }
tag == "Version" { print val, tag2val["Name"] }
' file
8.0.3.0 IBM SDK, Java Technology Edition, Version 8
9.0.5.3 IBM HTTP Server for WebSphere Application Server
。
$ cat file | awk -v OFS='\t' '
{ tag=val=$0; sub(/[[:space:]].*/,"",tag); sub(/[^[:space:]]*[[:space:]]+/,"",val); tag2val[tag]=val }
tag == "Version" { print val, (tag2val["Name"] ~ /WebSphere/ ? "WebSphere" : "JDK") }
' file
8.0.3.0 JDK
9.0.5.3 WebSphere
上面的代码是使用我的系统上没有的cat file
而不是使用您在问题中提供的内容作为输入来运行的:/ihs_home/HTTPServer/bin/versionInfo.sh
$ cat file
.....
Installed Product
--------------------------------------------------------------------------------
Name IBM SDK, Java Technology Edition, Version 8
Version 8.0.3.0
ID JAVA8
Build Level pxa6480sr3ifix-20160615_01
Build Date 06/15/16
Architecture x86-64 (64 bit)
Installed Product
--------------------------------------------------------------------------------
Name IBM HTTP Server for WebSphere Application Server
Version 9.0.5.3
ID IHS
Build Level f5032008.04
Build Date 2/26/20
Package com.ibm.websphere.IHS.v90_9.0.5003.20200226_0941
Architecture x86-64 (64 bit)
Installed Features Core runtime
--------------------------------------------------------------------------------
.....