Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 259
Rites Avatar asked Oct 12 '10 15:10

Rites


People also ask

How do you check whether server is up or down in command prompt?

At the command line, type in net statistics for a list of core performance data, such as network errors, hung sessions, bytes received, SMBs received/transmitted, write/read errors, etc. This includes all data since the last reboot—oh, and that also gives you the server's uptime!

What does == mean in batch file?

[ == ] (Double Equals) The "IF" command uses this to test if two strings are equal: IF "%1" == "" GOTO HELP. means that if the first parameter on the command line after the batch file name is equal to nothing, that is, if a first parameter is not given, the batch file is to go to the HELP label.

How do you check whether a service is running in Windows?

Windows has always used the Services panel as a way to manage the services that are running on your computer. You can easily get there at any point by simply hitting WIN + R on your keyboard to open the Run dialog, and typing in services. msc.


1 Answers

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."
like image 70
DMKing Avatar answered Sep 30 '22 06:09

DMKing