Windows服务器自动维护脚本

九月 14th, 2009 Posted in 1.操作系统, Windows | 阅读次数: 238 次

制作:高进波
时间:2009-09-14

windows server 2003中tomcat监听80端口,异常关闭.
解决方案:
间隔5分钟自动检测80端口是否监听,如果没有监听,自动启动tomcat,并写入日志文件

步骤:
1.编写BAT脚本
notepad e:\hugwww-check-tomcat.bat

rem ——————————————————————————
@echo off
title 自动检测tomcat运行情况,如关闭自动启动,power by hugwww
rem 设置时间格式,用来写入日志文件
DATE=%date:~0,10%
TIME=%time%

:start
rem 延时5分钟,保存端口信息,检测80是否监听并写入flage.txt文件,1为监听,0为无监听
rem 通过for循环读取flage.txt中的值并赋给flage变量
ping -n 300 -w 500 127.0.0.1>null
netstat -an | find “LIST”>e:\port.txt
type e:\port.txt|find /c “0.0.0.0:80 “|sort>e:\flage.txt
for /F %%F in (e:\flage.txt) do set FLAGE=%%F

goto flage%FLAGE%

:flage0
rem 处理无监听,写日志,自动启动tomcat
echo flage is %FLAGE%,服务关闭,时间%DATE% %TIME%>>e:\hugwww-tomcat-fail.log
call d:\start-tomcat.bat
goto start

:flage1
echo Flage is %FLAGE%,服务正常,时间%DATE% %TIME% >>e:\hugwww-tomcat-succes.log

goto start
echo 脚本完成

rem ——————————————————————————

说明:此文档适合于window xp,windows 2003,window 2008,win7,脚本内容还可以进一步优化,将tomcat启动脚本替换为自己的路径即可
可按照此脚本写出监听WINDOWS下任意端口,进行自动维护

注:type e:\port.txt|find /c “0.0.0.0:80 “|sort>e:\flage.txt 80后面有个空格,必须要有空格才能正确找出80端口是否监听

相关日志:

2 Responses to “Windows服务器自动维护脚本”

  1. Related Resources Says:

    Interesting Article…

    [...]some interesting sites worth visitng. We recommend all our readers go and check these out[...]……


  2. Degenerative Disc Disease Says:

    Websites we think you should visit…

    [...]although websites we backlink to below are considerably not related to ours, we feel they are actually worth a go through, so have a look[...]……


留下您的脚印