windows 使用批处理文件检查服务器是否已启动?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3916538/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Checking whether a server is up or not using batch file?
提问by Rites
I need to check whether a server is up or not? If down then i need to send an email And this task should be repeated in every 30mins.
我需要检查服务器是否启动?如果失败,那么我需要发送一封电子邮件,并且该任务应每 30 分钟重复一次。
I have to do this using batch file.
我必须使用批处理文件来做到这一点。
回答by DMKing
This batch file will get you most of the way there. You'll have to use blat or something similar or Windows script to send the email. Use the task scheduler to call the batch file every 30 minutes.
这个批处理文件将帮助您完成大部分工作。您必须使用 blat 或类似的东西或 Windows 脚本来发送电子邮件。使用任务计划程序每 30 分钟调用一次批处理文件。
checkserver.bat:
检查服务器.bat:
@echo off
ping -n 1 %1 > NUL
IF ERRORLEVEL 0 (echo "Up -- Don't send email.") ELSE echo "Down -- Send email."
Call it like so:
像这样称呼它:
C:\>checkserver 127.0.0.1
"Up -- Don't send email."
C:\>checkserver 128.0.0.1
"Down -- Send email."
回答by David Pokluda
You can try to access one of its filesystem shares or ping it if you know its IP address. That would be the easiest way and both of them doable from CMD.
如果您知道其 IP 地址,您可以尝试访问其文件系统共享之一或 ping 它。这将是最简单的方法,而且它们都可以通过 CMD 实现。
回答by ghostdog74
To check whether server is up, you can use the ping
command. To send email, you can download email tools like blat
etc. To repeat every 30mins, set it up using task scheduler.
要检查服务器是否已启动,您可以使用该ping
命令。要发送电子邮件,您可以下载诸如此类的电子邮件工具blat
。要每 30 分钟重复一次,请使用任务计划程序进行设置。