grjitdept
asked on
Help writing a VBScript to ping specific servers and then email results to an email address
Hi,
I'm looking to write a (hopefully) simple vbscript that will output the results of a ping command to a command line mailer.
We have a number of servers that are periodically updated and then have a scheduled restart around 11pm. I'd like to schedule this new script to 'ping' a number of specified servers, return a simple 'yes' or 'no' value for each one based on whether the ping was returned, then combine these answers into a single string which I will pass to a command line emailer (BMail) as the subject. I'll then get an email at home telling me that the servers are responding after the reboots.
Now I know there are easier ways of doing this and existing free monitoring tools, but I'm keen to practise my scripting so please humour me!
So for example, there are 3 servers to test:
SERV1
SERV2
SERV3
Assuming that Server 1 and 2 reboot fine, but 3 hangs, the output string I want will be:
SERV1: OK SERV2: OK SERV3: FAIL
I'm fine with basic vbscripting, variables, passing values to a shell command prompt etc, what I really need the help with is translating the results of a ping command into a simple yes/no answer. Is this even possible? Perhaps with error/reutrn codes? Any advice much appreciated!
Thanks
I'm looking to write a (hopefully) simple vbscript that will output the results of a ping command to a command line mailer.
We have a number of servers that are periodically updated and then have a scheduled restart around 11pm. I'd like to schedule this new script to 'ping' a number of specified servers, return a simple 'yes' or 'no' value for each one based on whether the ping was returned, then combine these answers into a single string which I will pass to a command line emailer (BMail) as the subject. I'll then get an email at home telling me that the servers are responding after the reboots.
Now I know there are easier ways of doing this and existing free monitoring tools, but I'm keen to practise my scripting so please humour me!
So for example, there are 3 servers to test:
SERV1
SERV2
SERV3
Assuming that Server 1 and 2 reboot fine, but 3 hangs, the output string I want will be:
SERV1: OK SERV2: OK SERV3: FAIL
I'm fine with basic vbscripting, variables, passing values to a shell command prompt etc, what I really need the help with is translating the results of a ping command into a simple yes/no answer. Is this even possible? Perhaps with error/reutrn codes? Any advice much appreciated!
Thanks
ASKER
That looks the sort of thing I'm after - though a little more advanced - I think the key in the example you've given me is the WMI Win32_Ping command. Could you help me simplify this a bit? Let's make it very simple. A single machine, SERV1 needs pinging and the results returning to a variable as either OK or FAIL....
I think if you add a machine in the text box and it will give you the ping results
regards
Chandru
regards
Chandru
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Absolutely spot on - and nice touch checking the C share as well - thanks!
Oops small rectification:
Since
strPingResults = LCase(objExec.StdOut.ReadA ll)
is Lcase (lowercase)
You if statement should be
IF InStr(strPingResults, "ttl") THEN
THanks!
Since
strPingResults = LCase(objExec.StdOut.ReadA
is Lcase (lowercase)
You if statement should be
IF InStr(strPingResults, "ttl") THEN
THanks!
ASKER
This didn't work first time I tried - seemed to be because you used the LCase function on the ping results but then checked for TTL in uppercase? I changed the TTL string to ttl and it seemed to work then.
You mentioned checking for availability of the C$ share. Any chance you could show me how to do that within this script? i.e. check ping AND check c$ share?
Thanks again
You mentioned checking for availability of the C$ share. Any chance you could show me how to do that within this script? i.e. check ping AND check c$ share?
Thanks again
Try this HTA
http://dm4ever1.googlepages.com/connectivitymonitor.zip
regards
Chandru