.bat file to check servers are up
12,928
For a simple check whether the server is up or not you could put all IP addresses in a file and call the following script with script.bat urls.txt
:
@echo off
for /f %%a in (%1) do (
echo Pinging %%a ...
ping -n 1 %%a | find "Reply" > NUL
if not errorlevel 1 (echo %%a is up) else (echo %%a is down)
)
urls.txt
should look like this (just a list of IP addresses of your servers or urls):
www.google.com
www.amazon.com
10.2.1.12
8.8.8.8
Related videos on Youtube
Comments
-
Rauf over 1 year
We are running ERP software which is deployed to number of servers. If we get a problem, we usually restart the servers and cross check that all the servers are running (just check if we get login page or not). Alternatively, we ping to IP address
192.XXX.X.XX
to check the 'reply'.This checking process is time consuming. How can I create a
.bat
file to check and give me results like192.XXX.X.XX:80 OK 192.XXX.X.XX:81 OK 192.XXX.X.YY:80 No Reply
-
Rauf over 7 yearsI tried this. But where I can find the result ? I ran 'cmd', then put script.bat urls.txt. The cmd did not give me any result.
-
DavidPostill about 7 yearsHave you actually tested this? This batch file contains at least 4 mistakes.
-
cmtjk about 7 years@Rauf, I updated the script
-
cmtjk about 7 years@DavidPostill, no I'm not on a Windows machine but the new script should work. feel free to edit!
-
DavidPostill about 7 years@r3r57 Revised script works. Please test next time :)
-
Bruno Vincent about 5 yearsHow do your run this? If my files are in this directory: C:/BatchPing/url.txt C:/BatchPing/script.bat I know what to put in URL, but what do I put into .bat file? Also, what would be the exact code for this situation? Do I need to substitute %%a and %1 with something?
-
Ghulam Akbar about 4 yearsThe above script works fine. But if ping is prohibited for some URL/server, this batch script doesn't work. In this case, what should be the modified script ...?
-
mivk over 3 yearsYou should probably use
find "TTL="
instead offind "Reply"
. -
Maris B. over 3 years@mivk is right. For IPv4 the "TTL=" is the most reliable method. The "Reply" is found even when there is an error "Destination host unreachable". Check this thread for more info: stackoverflow.com/questions/9329749/…