Results 1 to 5 of 5

Thread: send mail if ping fails

  1. #1
    Join Date
    Jan 2009
    Posts
    3

    send mail if ping faile

    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 ?

  2. #2
    Pegasus \(MVP\) Guest

    Re: send mail if ping fails


    "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.



  3. #3
    Join Date
    Jan 2009
    Posts
    3

    Re: send mail if ping faile

    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.

    ?

  4. #4
    OldDog Guest

    Re: send mail if ping fails

    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 ------------------->

  5. #5
    Pegasus \(MVP\) Guest

    send mail if ping fails


    "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.



Similar Threads

  1. Replies: 3
    Last Post: 09-09-2010, 12:01 AM
  2. Replies: 2
    Last Post: 24-08-2010, 10:16 AM
  3. Not able to Ping or net send
    By Harsh01 in forum Networking & Security
    Replies: 4
    Last Post: 31-03-2009, 10:33 AM
  4. Replies: 3
    Last Post: 03-07-2008, 06:07 PM
  5. Ping fails to resolve name but nslookup OK
    By AXJ in forum Windows Server Help
    Replies: 5
    Last Post: 18-04-2008, 11:08 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,750,668,002.21590 seconds with 16 queries