I basically want to have a windows batch script which goes through a list of servers and checks every server with a ping if it is online. The list of servers should be a simple plain text file and should look something like this:
...
"Google" www.google.com
"Node1" 221.12.123.1
"Download Server" dl.myserver.com
"Login Server" login.myserver.com
...
Here is a simple rundown what the program should do:
- print a list of the descriptions of all the servers in the list to the screen.
- ping the first server server 4 times if one ping succeeds it should return online if all 4 pings fail it should return offline.
- print online or offline next to the first server in the printed list
- run step 2 and 3 for all other servers in the list.
The output should look like the following:
...
Google: online
Stackoverflow: online
Node1: online
Download Server: offline
Login server: offline
...
I just want to know if this is even possible in (windows) batch and how to do it. If it isn't possible in batch, what programming language should I use? Would it be possible to program this in Python?
I would also be really thankful if anybody could post the code how to do this, Thanks!
This can be done easily in batch, you just need some
for /f
loops,echo
statements,if
statements,goto
/call
statements and use theping
command.You can use
echo
statement for this, likeecho "Google" www.google.com
inside a
for /f
loop [likefor /f "tokens=5 delims==, " %%p in (
], you can use theping
command with 4 trys like soping -n 4 www.google.com
you can use and
if
statemenet here, like so:if "%status%"=="online" echo Google: online
or justecho Google: %status%
You can use a
goto
or acall
statement here (use it like a function), for example:call :server_status_function www.google.com