检查Web服务器和从配置文件中同一台服务器上未解析这两个80端口以及8080端口 [英] Checking web servers and is not parsing both port 80 as well as port 8080 from configuration files on same server

查看:233
本文介绍了检查Web服务器和从配置文件中同一台服务器上未解析这两个80端口以及8080端口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

研究结果今天这个..

REF = 如何解析批量xml文件(CMD)
注:从杰布的注释,以帮助从XML解析出的端口号

REF = How to parse xml file in batch (CMD) NOTE: The comment from jeb to help parse out the port number from xml

SET results=%CD%\somelog.log

IF EXIST %results% DEL %results%

REM NOTE: THIS IS ALL ONE LINE!!!!  ALL THE WAY DOWN TO THE PAUSE STATMENT.
FOR /F "usebackq tokens=1" %%q in (`reg query \\some_server\HKLM\SYSTEM\CurrentControlSet\services ^| find /i "tomcat"`) DO
FOR /F "usebackq tokens=3" %%a in (`reg query \\some_server\HKLM\SYSTEM\CurrentControlSet\services\%%~nxq /v ImagePath`) DO
FOR /F "tokens=1-2,* delims=:\" %%1 IN ("%%a") DO
FOR /F tokens^=1^,2^ delims^=^" %%A IN ('..\grep -m 1 "\<Connector port\=" \\some_server\%%1$\%%2\conf\server.xml') DO
ECHO "CHECKING WEB PAGE CONTENT FROM URL http://some_server:%%B/server_page.htm" 1>> %results% &&
..\WGET -q "http://some_server:%%B/server_page.htm" -O - | ..\GREP "Configuration framework is not loaded" 2>> %results% &&
..\WGET -q "http://some_server:%%B/server_page.htm" -O - | ..\GREP "Successfully acquired a database connection" 3>> %results% 

pause

当前结果:被所产生的数据被重定向到日志文件,但与管道WGET通过使用grep的结果是没有捕捉到日志

Current Result: is the resulting data is being redirected to the log file, but the results of the WGET with the Pipe through using GREP is not capturing to the log.

曾尝试:
结果>>日志
结果1 >>日志
结果2 2 >>日志
result3 3 >>日志

Have tried: result >> log result 1>> log result2 2>> log result3 3>> log

和只捕获了最终结果的echo命令的结果。

And is only capturing the result of the ECHO command in the final results.

起点: 2014年12月5日

Starting point: 2014-12-05

让我们明白,为什么我们没有得到serverport。我已经想通了这一点,但现在我需要弄清楚了这一点,如何获得第一个%serverport%。按照要求,我已删除FINDSTR和涨使用grep。

Let's figure out why we are not getting the serverport. I have figured this out, but now I need to figure this out and how to get to the first %serverport%. As requested, I have removed FINDSTR and have gone with GREP.

具体做法是:

REM >>  here is the problem: if we want to break out for the first port
SET serverport=%%B && GOTO :BREAK)
    :break
    SET serverport=%serverport: protocol=%
    SET serverport=%serverport:"=%

和是因为我们打出来的剧本,它不能够继续,因为Apache Tomcat上的第二个实例:

And is because we break out of the script, it is not able to continue to the second instance of Apache Tomcat because of:

FOR /F "tokens=1-2* delims==" %%A IN ('..\grep "\<Connector port\=" %tpath%') DO (
    SET serverport=%%B
    goto :break
    )
    :break
    SET serverport=%serverport: protocol=%
    SET serverport=%serverport:"=%

所以..让我们来看看是怎么回事。

So.. Let's see what is going on here..

第1步后,让我们创建一个DEBUG批处理脚本。这会抢在Windows服务名称服务器密钥。例如,当您运行NET STOP的tomcat6或NET START tomcat6中。我们不希望完整的注册表路径,只是键名。试图确定在文件系统中的文件夹名时,我们可以使用相同的构建体,但是这是从注册表

Step 1, Let's create a DEBUG Batch Script. This will grab the server key for the Windows Service Name. For example, when you run NET STOP tomcat6 or NET START tomcat6 .. We don't want the full registry path, but just the key name. We can use the same construct when trying to determine a folder name in the file system, but this is from the registry.

echo test 1

FOR /F "usebackq tokens=1" %%q in (`reg query \\some_server\HKLM\SYSTEM\CurrentControlSet\services ^| find /i "tomcat"`) DO echo %%~nxq

echo end of test 1

第1步的结果,让我们看看我们借此does..If tester.bat> RESULTS.TXT我们看到:

Step 1 results, Let's see what this does..If we take tester.bat > results.txt we see:

D:\WORK\Scripts\test>echo test 1 
test 1

D:\WORK\Scripts\test>FOR /F "usebackq tokens=1" %q in (`reg query \\some_server\HKLM\SYSTEM\CurrentControlSet\services | find /i "tomcat"`) DO echo %~nxq 

D:\WORK\Scripts\test>echo tomcat6_1 
tomcat6_1

D:\WORK\Scripts\test>echo tomcat6_2 
tomcat6_2

D:\WORK\Scripts\test>echo end of test 1 
end of test 1

第2步,让我们看看我们得到什么,当我们开始寻找服务器端口..
注意:每个FOR行都是一条线。对于。在.. DO ..适用。在.. DO ..适用。在.. DO ..适用。在.. DO ...(是的,这是他们全部四个在一行中)

Step 2, let's see what we get when we start looking for the server port.. NOTE:Each FOR line is all one line.. FOR.. IN.. DO.. FOR.. IN.. DO.. FOR.. IN.. DO.. FOR.. IN.. DO... (yes, that is four of them all in one line)

echo test 2

FOR /F "usebackq tokens=1" %%q in (`reg query \\some_server\HKLM\SYSTEM\CurrentControlSet\services ^| find /i "tomcat"`) DO
FOR /F "usebackq tokens=3" %%a in (`reg query \\some_server\HKLM\SYSTEM\CurrentControlSet\services\%%~nxq /v ImagePath`) DO
FOR /F "tokens=1-2,* delims=:\" %%1 IN ("%%a") DO
FOR /F "tokens=1-2* delims==" %%A IN ('..\grep "\<Connector port\=" \\some_server\%%1$\%%2\conf\server.xml') DO (SET serverport=%%B)
echo end of test 2

echo we are done

第2步结果,让我们看看我们借此does..If tester.bat> RESULTS.TXT我们看到:

Step 2 results, Let's see what this does..If we take tester.bat > results.txt we see:

D:\WORK\Scripts\test>echo test 2 
test 2

D:\WORK\Scripts\test>FOR /F "usebackq tokens=1" %q in (`reg query \\some_server\HKLM\SYSTEM\CurrentControlSet\services | find /i "tomcat"`) DO FOR /F "usebackq tokens=3" %a in (`reg query \\some_server\HKLM\SYSTEM\CurrentControlSet\services\%~nxq /v ImagePath`) DO FOR /F "tokens=1-2,* delims=:\" %1 IN ("%a") DO FOR /F "tokens=1-2* delims==" %A IN ('..\grep "\<Connector port\=" \\some_server\%1$\%2\conf\server.xml') DO (SET serverport=%B ) 

D:\WORK\Scripts\test>FOR /F "usebackq tokens=3" %a in (`reg query \\some_server\HKLM\SYSTEM\CurrentControlSet\services\tomcat6_1 /v ImagePath`) DO FOR /F "tokens=1-2,* delims=:\" %1 IN ("%a") DO FOR /F "tokens=1-2* delims==" %A IN ('..\grep "\<Connector port\=" \\some_server\%1$\%2\conf\server.xml') DO (SET serverport=%B ) 

D:\WORK\Scripts\test>FOR /F "tokens=1-2,* delims=:\" %1 IN ("d:\tomcat_1\bin\tomcat6.exe") DO FOR /F "tokens=1-2* delims==" %A IN ('..\grep "\<Connector port\=" \\some_server\%1$\%2\conf\server.xml') DO (SET serverport=%B ) 

D:\WORK\Scripts\test>FOR /F "tokens=1-2* delims==" %A IN ('..\grep "\<Connector port\=" \\some_server\d$\tomcat_1\conf\server.xml') DO (SET serverport=%B ) 

D:\WORK\Scripts\test>(SET serverport="80" protocol ) 

D:\WORK\Scripts\test>(SET serverport="8443" protocol ) 

D:\WORK\Scripts\test>(SET serverport="8009" protocol ) 

D:\WORK\Scripts\test>FOR /F "usebackq tokens=3" %a in (`reg query \\some_server\HKLM\SYSTEM\CurrentControlSet\services\tomcat6_2 /v ImagePath`) DO FOR /F "tokens=1-2,* delims=:\" %1 IN ("%a") DO FOR /F "tokens=1-2* delims==" %A IN ('..\grep "\<Connector port\=" \\some_server\%1$\%2\conf\server.xml') DO (SET serverport=%B ) 

D:\WORK\Scripts\test>FOR /F "tokens=1-2,* delims=:\" %1 IN ("d:\tomcat_2\bin\tomcat6.exe") DO FOR /F "tokens=1-2* delims==" %A IN ('..\grep "\<Connector port\=" \\some_server\%1$\%2\conf\server.xml') DO (SET serverport=%B ) 

D:\WORK\Scripts\test>FOR /F "tokens=1-2* delims==" %A IN ('..\grep "\<Connector port\=" \\some_server\d$\tomcat_2\conf\server.xml') DO (SET serverport=%B ) 

D:\WORK\Scripts\test>(SET serverport="8080" protocol ) 

D:\WORK\Scripts\test>(SET serverport="8443" protocol ) 

D:\WORK\Scripts\test>(SET serverport="8010" protocol ) 

D:\WORK\Scripts\test>echo end of test 2 
end of test 2

D:\WORK\Scripts\test>echo we are done 
we are done

我只希望服务器端口的第一个实例。

I only want the first instance of the server port.

该服务器具有的tomcat的两个实例:
80端口
端口8080

This server has two instances of tomcat: port 80 port 8080

这将是简单,如果这只是这一个服务器,但我有30台服务器我要报告的。

It would be simple if it was just this one server, but I have 30 servers I want to report on.

推荐答案

确定。我是pretty肯定,我可以创建一个这样的答案。随着嵌套FOR..IN..DO结构四次,我想这就是为什么我不能够运行wget和只有第一个ECHO工程..这里是我们在这个code。

OK. I am pretty sure that I can create an answer for this. With the nested FOR..IN..DO structures four times, I think that is why I am not able to run the WGET and only the first ECHO works.. Here is where we are at with this code.

REF 如何解析批处理(CMD) xml文件
注意:从@jeb的注释,以帮助从XML解析出的端口号

REF How to parse xml file in batch (CMD) NOTE: The comment from @jeb to help parse out the port number from xml

SET servers=%CD%\monitored_computers.txt
SET results=%CD%\somelog.log

IF EXIST %results% DEL %results%

FOR /f "tokens=2-8 delims=.:/ " %%a IN ("%date% %time: =0%") DO ECHO PROCESS CHECK STARTED %%a/%%b/%%c %%d:%%e:%%f.%%g >> %results%
    FOR /F "tokens=1-2* delims=," %%A IN (%servers%) DO (
        REM NOTE: THIS IS ALL ONE LINE!!!!  ALL THE WAY DOWN TO THE PAUSE STATMENT.
        FOR /F "usebackq tokens=1" %%q in (`reg query \\%%A\HKLM\SYSTEM\CurrentControlSet\services ^| find /i "tomcat"`) DO
        FOR /F "usebackq tokens=3" %%a in (`reg query \\%%A\HKLM\SYSTEM\CurrentControlSet\services\%%~nxq /v ImagePath`) DO
        FOR /F "tokens=1-2,* delims=:\" %%1 IN ("%%a") DO
        FOR /F tokens^=1^,2^ delims^=^" %%H IN ('..\grep -m 1 "\<Connector port\=" \\%%A\%%1$\%%2\conf\server.xml') DO
        ECHO "http://%%A:%%I/some_page.htm" >> %CD%\servers.txt
            pause
    )

希望这可以帮助别人。

Hope this helps somebody.

这篇关于检查Web服务器和从配置文件中同一台服务器上未解析这两个80端口以及8080端口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆