开发者

Checking whether a server is up or not using batch file?

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.

I have开发者_运维问答 to do this using batch file.


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.

checkserver.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."


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.


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.


You can check whether the machine replies to ping. But because ping on Windows doesn't return a useful %errorlevel%, you need to pipe it's output through find.

Example:

ping -4 -n 2 YourIPorHostname | find "TTL=" >NUL && echo OK

or

ping -4 -n 2 YourIPorHostname | find "TTL=" >NUL || echo No reply

To send an email, you need some additional program.

(if you also have a Unix machine on your network, the whole thing would be much easier from there, since the "crontab" scheduler automatically sends emails)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜