hello to all!
i need script do it :
ping to server
if pink ok - ping again (loop)
if ping fail - send mail via telnet
http://www.f2h.co.il/im.php?name=Ping.jpg&src=95181098
Server 2003 R2
vb?
Bat ?
Printable View
hello to all!
i need script do it :
ping to server
if pink ok - ping again (loop)
if ping fail - send mail via telnet
http://www.f2h.co.il/im.php?name=Ping.jpg&src=95181098
Server 2003 R2
vb?
Bat ?
"skepper" <[email protected]> wrote in message
news:[email protected]...
>
> hello to all!
>
> i need script do it :
>
> ping to server
> if pink ok - ping again (loop)
> if ping fail - send mail via telnet
>
> http://www.f2h.co.il/im.php?name=Ping.jpg&src=95181098
>
> Server 2003 R2
> vb?
> Bat ?
> --
> skepper
You could try this batch file:
@echo off
:Again
ping server | find /i "bytes=" || goto Fail
ping localhost -n 60 > nul
goto Again
:Fail
blat.exe /.. /.. /..
Blat.exe is a command line mailer that you can download from a number of
sites.
i try it:
PingTest.cmd
----------------------------------------------------
@echo off
:Again
ping mis | find /i "bytes=" || goto Fail
ping localhost -n 60 > nul
goto Again
:Fail
call mail.vbs
----------------------------------------------------
the mail.vbs is:
Set objEmail = CreateObject("CDO.Message")
objEmail.From = "[email protected]"
objEmail.To = "[email protected]"
objEmail.Subject = !Attention Message!"
objEmail.Textbody = "Ping to Server Fail!"
objEmail.Send
if i remove the line @echo off, i get this masage :
ping server| find /i "bytes=" || goto Fail
ping server| find /i "bytes=" || goto Fail
ping server| find /i "bytes=" || goto Fail
ping server| find /i "bytes=" || goto Fail
The process tried to write to a nonexistent pipe.
The process tried to write to a nonexistent pipe.
The process tried to write to a nonexistent pipe.
?
On Jan 28, 10:11 am, "Pegasus \(MVP\)" <[email protected]> wrote:
> "skepper" <[email protected]> wrote in message
>
> news:[email protected]...
>
>
>
>
>
>
>
> > hello to all!
>
> > i need script do it :
>
> > ping to server
> > if pink ok - ping again (loop)
> > if ping fail - send mail via telnet
>
> >http://www.f2h.co.il/im.php?name=Ping.jpg&src=95181098
>
> > Server 2003 R2
> > vb?
> > Bat ?
> > --
> > skepper
>
> You could try this batch file:
> @echo off
> :Again
> ping server | find /i "bytes=" || goto Fail
> ping localhost -n 60 > nul
> goto Again
>
> :Fail
> blat.exe /.. /.. /..
> Blat.exe is a command line mailer that you can download from a number of
> sites.- Hide quoted text -
>
> - Show quoted text -
Or in vbScript, try this one. Watch the wraps.
<------ Begin script ------------------>
strComputer = "Server name or IP" ' Server you are watching
Do While 1<2 'This loop will run forever (i.e., until the script is
manually stopped).
If IsConnectible (strComputer,"","") Then
WScript.Sleep 60000 ' wait a minute
Else
adminmail = "[email protected]" ' Who you want it sent to
'
smtp = "172.18.100.55" ' smtp mail server name or IP
Set mailing = CreateObject("CDO.Message")
Set wshNet = CreateObject("WScript.Network")
mailing.From = ("[email protected]")
mailing.To = adminmail
mailing.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/
configuration/sendusing") = 2
mailing.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/
configuration/smtpserver") = smtp
mailing.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/
configuration/smtpserverport") = 25
mailing.Subject = header & "Ping failed for" & strComputer
mailing.TextBody = sFullProductionMessage
mailing.Configuration.Fields.Update
mailing.Send
On Error Goto 0
End If
Loop
Function IsConnectible(strHost, intPings, intTO)
' Returns True if strHost can be pinged.
' Based on a program by Alex Angelopoulos and Torgeir Bakken.
Dim objFile, strResults
If intPings = "" Then intPings = 2
If intTO = "" Then intTO = 750
Const OpenAsDefault = -2
Const FailIfNotExist = 0
Const ForReading = 1
objShell.Run "%comspec% /c ping -n " & intPings & " -w " & intTO _
& " " & strHost & ">" & strTempFile, 0, True
Set objFile = objFSO.OpenTextFile(strTempFile, ForReading, _
FailIfNotExist, OpenAsDefault)
strResults = objFile.ReadAll
objFile.Close
Select Case InStr(strResults, "TTL=")
Case 0
IsConnectible = False
Case Else
IsConnectible = True
End Select
If objFSO.FileExists(strTempfile) Then
objFSO.DeleteFile(strTempFile)
End If
End Function
<------------ End Script ------------------->
"skepper" <[email protected]> wrote in message
news:[email protected]...
>
> i try it:
>
> PingTest.cmd
> ----------------------------------------------------
> @echo off
> :Again
> ping mis | find /i "bytes=" || goto Fail
> ping localhost -n 60 > nul
> goto Again
>
> :Fail
> call mail.vbs
> ----------------------------------------------------
> the mail.vbs is:
> Set objEmail = CreateObject("CDO.Message")
> objEmail.From = "[email protected]"
> objEmail.To = "[email protected]"
> objEmail.Subject = !Attention Message!"
> objEmail.Textbody = "Ping to Server Fail!"
> objEmail.Send
>
> if i remove the line @echo off, i get this masage :
> ping server| find /i "bytes=" || goto Fail
> ping server| find /i "bytes=" || goto Fail
> ping server| find /i "bytes=" || goto Fail
> ping server| find /i "bytes=" || goto Fail
> The process tried to write to a nonexistent pipe.
> The process tried to write to a nonexistent pipe.
> The process tried to write to a nonexistent pipe.
>
> ?
>
>
> --
> skepper
> ------------------------------------------------------------------------
> skepper's Profile: http://forums.techarena.in/members/skepper.htm
> View this thread: http://forums.techarena.in/server-scripting/1111495.htm
>
> http://forums.techarena.in
>
Try this batch file for starters:
@echo off
:Again
ping mis | find /i "bytes=" || goto Fail
ping localhost -n 60 > nul
goto Again
:Fail
echo Ping failed!
Does it work?
==================
I have a few problems with your VB Script. Here they are:
1. Instead of writing
call mail.vbs
you should write
script //nologo c:\mail.vbs
2. Your script lacks the details that are required under
objEmail.Configuration.Fields
3. The line
objEmail.Subject = !Attention Message!"
lacks a double quote after the = character.
If you are not familiar with VB Scripts then you would be much better off
using blat.exe, as I suggested in my first reply.