我正在编写一个(批处理文件或VBScript)来很好地关闭Windows服务器上所有正在运行的WebSphere JVM,但需要一些文本处理方面的帮助 . 我希望脚本运行并解析"serverstatus"命令的输出以获取框中的 Application Servers 的名称,并将匹配(带回车符)存储在变量中以供脚本的其余部分使用 .
示例命令输出:
C:\WebSphere\AppServer\bin>serverstatus -all
ADMU0116I: Tool information is being logged in file
C:\WebSphere\AppServer\profiles\MySrv01\logs\serverStatus.log
ADMU0128I: Starting tool with the MySrv01 profile
ADMU0503I: Retrieving server status for all servers
ADMU0505I: Servers found in configuration:
ADMU0506I: Server name: MyCluster_MySrv01
ADMU0506I: Server name: MyCluster_MySrv01_1
ADMU0506I: Server name: MyNextCluster_MySrv04
ADMU0506I: Server name: MyNextCluster_MySrv04_1
ADMU0506I: Server name: nodeagent
ADMU0508I: The Application Server "MyCluster_MySrv01" is STARTED
ADMU0508I: The Application Server "MyCluster_MySrv01_1" is STARTED
ADMU0508I: The Application Server "MyNextCluster_MySrv04" is STARTED
ADMU0509I: The Application Server "MyNextCluster_MySrv04_1" cannot be
reached. It appears to be stopped.
ADMU0508I: The Node Agent "nodeagent" is STARTED
- nodeagent不应该匹配 . 对于我是否要针对所有应用服务器或只是那些状态为“已启动”的应用服务器,评审团仍然没有考虑 .
2 回答
这是使用Regex的替代方法 . 它只是读取stdout并处理所有已启动的应用程序服务器 - 应用程序服务器存储在名为AppServers的数组中 . 在W2K3上测试过 . 编辑:我们添加了一种通过添加日志写入功能 (don't forget to add the const ForAppending at the start of the script that we have just added to this answer) 将输出记录到文件的方法 . 日志写入功能采用以下格式:
这是一个粗略的功能,但你做的是什么 . 我希望有所帮助 . :)
使用RegExp从输入中删除引用的名称;添加上下文 - 服务器,已启动 - 微调结果集 . 在代码中:
输出: