Tomcat自动重启脚本命令Window_Linux实践

将此下面的代码保存到一个.txt文件中,然后将后缀名命名为.vbs,再然后双击运行即可。

 

注意要修改的地方:

 

1.检查tomcat是否挂掉的访问路径,即下面代码中的:http://paidan.mrifx.cn?a=" & now

 

2.一定要先切到bat所在目录 WshShell.CurrentDirectory="tomcat路径bin/即可",否则导致闪退

 

代码:

https://blog.csdn.net/iceylin/article/details/81109630

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

on   error   resume   Next       

 

Dim   a

  

a   =   True    

  

set   WshShell   =   WScript.CreateObject("WScript.Shell"

  

set fso=createobject("scripting.filesystemobject")

  

Do   While   a     

  

set   http   =   CreateObject("Microsoft.XMLHTTP")      

  

http.open   "GET","http://paidan.mrfix.cn?a=" & now,false 

  

http.send       

  

if   http.Status <> 200   Then  

  

'一定要先切到bat所在目录

WshShell.CurrentDirectory="D:\apache-tomcat-diaodu-7.0.50\bin\"

  

shutdown="D:\apache-tomcat-diaodu-7.0.50\bin\shutdown.bat"

  

WshShell.Run "cmd /c "& Chr(34) & shutdown & Chr(34)

  

WScript.Sleep(5000)          

  

startup="D:\apache-tomcat-diaodu-7.0.50\bin\startup.bat"

  

WshShell.Run "cmd /c"& Chr(34) & startup & Chr(34)

  

if (fso.fileexists("C:\tomcat重启记录文件.txt")) then

'打开文件,参数1为forreading,2为forwriting,8为appending

set file=fso.opentextfile("C:\tomcat_log.txt",8,true)

file.writeline "tomcat:" 

file.writeline now

file.writeline "chong xin qi dong" 

ts.writeblanklines 2 

file.close   

else

'创建文件,参数1为forreading,2为forwriting,8为appending

set file=fso.createtextfile( "C:\tomcat_log.txt",2,ture)

  

'写入文件内容,有三种方法:write(x)写入x个字符,writeline写入换行,writeblanklines(n)写入n个空行

file.writeline "tomcat:" 

file.writeline now

file.writeline "chong xin qi dong" 

file.writeblanklines 2 

file.close   

end if      

end if 

WScript.Sleep(300000)  

  

loop

 

 

这些运行好了,就直接运行运行这个vbs脚本,只要服务器宕机,它就能自动重启tomcat.并记录日志。(由于是中文名,导致创建文件乱码,所以建议在fso.createtextfile( "C:\tomcat重启记录文件.txt",2,ture)里用英文字母。)

 

image.png

 

 

关闭vbs代码:cmd.exe /C taskkill.exe /F /IM "wscript.exe" & taskkill.exe /F /IM "cscript.exe"

 

本站博客:www.wurao.xin

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值