|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Hi all - Self professed scripting newbie here. I'm trying to write a simple DOS script that will tell me very quickly which servers are up/down (after 3 power outages in one weekend, it would be nice to have a quick snapshot of what's up/down instead of waiting for our monitoring software to come up and start polling). Here's what I've got so far:
@echo off FOR %%a in (server1,server2,server3) DO PING -w 1000 -n 1 %%a |find "TTL=" && ECHO %%a is alive FOR %%a in (server1,server2,server3) DO PING -w 1000 -n 1 %%a |find "timed" && ECHO %%a Not Pingable! FOR %%a in (server1,server2,server3) DO PING -w 1000 -n 1 %%a |find "check" && ECHO Cannot resolve IP address for %%a! It actually works fine, but being the perfectionist that I am (yeah, right!), there are a few tweaks that I'd like to make, and I don't know how: 1) Have the script use a single list of servers, rather than having to specify server1,server2,server3 etc in each command. The list should NOT be an external file - I want to specify server names in the script to make it more easily portable, but I only want to specify them once. 2) Hide the ping output from standard out and only display the message specified. In other words, right now a successful ping will display this: Reply from 192.168.1.10: bytes=32 time<1ms TTL=127 server1 is alive I'd rather have it hide the reply and say only "server1 is alive." Sounds like a minor nit, but some of the people who will be using this script will be 1st level Help Desk folks, and they are easily confused. I don't want them to have to look at IP addresses and TTLs. 3) Leave the command window open after the script completes. Help Desk people may not remember to open cmd first and then run the script. If they double-click it in its current form, it will do its thing and then go away and they will think it didn't work. Any help is appreciated! Thanks! -Diggity |
|
#2
|
||||
|
||||
|
not sure about the rest, but in order to keep the cmd window open, use 'pause' at the end, this will require them to hit a key to continue
__________________
Come JOIN the party!!! Quote of the Month: Retirement: Because you've given so much of yourself to the company that you don't have anything left we can use. Questions to Ponder: What do you do when you see an endangered animal eating an endangered plant? iif([sarcasm]=true,iif([you have to ask]=true,"didn't work","ha ha ha"),"not sarcasm") copyright© 2008 sbenj69 |
|
#3
|
|||
|
|||
|
Take a look around google, there are free downloadable server monitor programs that can alert you when a server goes off the air. Also network scanners are available, nmap on linux is very good and I see there is a windows version.
__________________
====== Doug G ====== I didn't attend the funeral, but I sent a nice letter saying I approved of it. --Mark Twain |
|
#4
|
|||
|
|||
|
Quote:
Thanks Doug, I've gone that route already. Tried BigBrother and FreePing. Both work great, as does our enterprise NMS, Microsoft Operations Manager. They don't exactly fit the bill though. I need a portable script that can be run by anyone in IT without having to check an NMS and will instantly give a snapshot of what's up/down. The thing I neglected to mention is that the script will also echo out a series of "checklist" items for whomever is the first one to respond when the power comes back on. Stuff like: echo Don't forget to check air conditioners in network closets! echo Make sure hallway emergency lights are on in Building XYZ. echo Log in to application X and make sure that blah blah blah. Thanks! -Diggity |
|
#5
|
||||
|
||||
|
You're beginning to get outside of the realm of NT scripting here. It's not designed to capture command output (from ping.exe)
Use WSH instead.
__________________
Click the image if at any point you don't like my decision.Scripting problems? Windows questions? Ask the Windows Guru! |
|
#6
|
|||
|
|||
|
i pieced together bits of script to allow me to ping a list of computer names that are in a spreadsheet. You could easily manipulate this code to have the server names hard-coded in there. And instead of moving to another cell to mark it as "Found" then you could have MSGBOX statements to echo the information you wanted.
Mine just verifies that it should be in AD. If it does not return a 172 in the address, it is "Not Found". Either way - this code can be altered to fit your needs easily enough. Code:
Dim objshell, objWshScriptExec, objStdOut, strOutput
ActiveCell.Select
Do While ActiveCell > ""
Set objshell = CreateObject("WScript.Shell")
Set objWshScriptExec = objshell.Exec("ping " + ActiveCell + " -n 1")
Set objStdOut = objWshScriptExec.StdOut
'MsgBox strOutput
strOutput = objStdOut.ReadAll
Set objshell = Nothing
Set objWshScriptExec = Nothing
Set objStdOut = Nothing
Dim result
result = InStr(strOutput, "172.")
ActiveCell.Offset(0, 1).Select
If result = 0 Then
ActiveCell.Value = "Not Found"
Else
ActiveCell.Value = "Found"
End If
ActiveCell.Offset(1, -1).Select
Loop
'MsgBox result
|
![]() |
| Viewing: ASP Free Forums > System Administration > Windows Scripting > Newbie's ping script |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|