Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Need to create a batchfile, which sends Alerts  (Read 29030 times)

0 Members and 1 Guest are viewing this topic.

Alok_Kumar

  • Guest
Need to create a batchfile, which sends Alerts
« on: February 13, 2007, 11:34:21 PM »


Dear All,

I need to create a batch file, which should first ping to the different i.p address, if it gets request time out from any of them, it should send mail with specific massage. Your swift response wouold be highly appriciated.

hare krishna
Alok

Dilbert

  • Moderator


  • Egghead

  • Welcome to ComputerHope!
  • Thanked: 44
    Re: Need to create a batchfile, which sends Alerts
    « Reply #1 on: February 13, 2007, 11:38:56 PM »
    Good news and bad news.

    Good news: It is possible to parse a ping for a timeout. You can do this by outputting the ping results to a text file and trying to find the word "timeout" in the text file.

    Bad news: It is impossible to use DOS to send an email. DOS is too old, I'm afraid.
    "The geek shall inherit the Earth."

    Alok_Kumar

    • Guest
    Re: Need to create a batchfile, which sends Alerts
    « Reply #2 on: February 14, 2007, 12:11:24 AM »

    Thanks Dilbirt,

    So any work around of my problem ?

    hare krishna
    Alok

    ghostdog74



      Specialist

      Thanked: 27
      Re: Need to create a batchfile, which sends Alerts
      « Reply #3 on: February 14, 2007, 03:36:13 AM »
      you can use command line tools for sending emails such as blat

      then do something like this assuming only 2 ips. (substitute the blat command as desired)
      Code: [Select]
      @echo off
      set ip=10.10.10.11 10.10.20.2
      for /F  "tokens=1* delims= " %%i in ("%ip%") do (
            ping -n 2 %%i > nul
            if errorlevel 1 echo fail
            ping -n 2 %%j > nul
            if errorlevel 1 echo fail
      )

      Alok_Kumar

      • Guest
      Re: Need to create a batchfile, which sends Alerts
      « Reply #4 on: February 14, 2007, 04:36:08 AM »


      Thank Ghost,

      I did get success to send mail through blat, but I am still not able to figure out, how I can use your script in a btchfile, which triggers automatically and send mail back to me
      indicating a perticular i.p unable to ping. I've used the given below command to send mail
      thanks, once again.


       blat c:\emp.txt -to [email protected] -subject "Test"

      hare krishna
      Alok

      gpl



        Apprentice
      • Thanked: 27
        Re: Need to create a batchfile, which sends Alerts
        « Reply #5 on: February 14, 2007, 05:20:57 AM »
        If you are running on a modern windows system, you could always use a bit of vbs to send the email and call the vbs from your batch using START....

        Graham

        Alok_Kumar

        • Guest
        Re: Need to create a batchfile, which sends Alerts
        « Reply #6 on: February 14, 2007, 10:19:50 PM »


        Thanks Gpl,

        can't I use, batch programming to achieve this, because, I don't have V.B in my system.
        Please advise me, how can implement the above given logic in my last post through batch file programming.

        hare krishna
        Alok

        Sidewinder



          Guru

          Thanked: 139
        • Experience: Familiar
        • OS: Windows 10
        Re: Need to create a batchfile, which sends Alerts
        « Reply #7 on: February 15, 2007, 08:19:01 AM »
        Code: [Select]
        @echo off
        set ip=10.10.10.11 10.10.20.2
        for /F  "tokens=1* delims= " %%i in ("%ip%") do (
              ping -n 2 %%i > nul
              if errorlevel 1 (
                      set msg=Ping failed: %%i
                      blat c:\emp.txt -to [email protected] -subject %msg%
                     )
        )
        VBScript is installed with all Windows versions except Win95A. The current version is 5.6.

        Good luck.  8-)

        PS. Sending an email with VBScipt has been posted many times. If you need furthur assistance let us know and yes, you can launch a VBScript from a batch file.

        PSS. For your own protection, it  is not a good idea to post email addresses.
        The true sign of intelligence is not knowledge but imagination.

        -- Albert Einstein

        Alok_Kumar

        • Guest
        Re: Need to create a batchfile, which sends Alerts
        « Reply #8 on: February 19, 2007, 05:10:45 AM »


        Thanks Winder,

        Can you explain in brief of each step in your script. I've tested your script, but it's not working. though, when using only blat, I can send mail. pleas suggest, what causes this script to fail?

        hare krishna
        Alok

        Sidewinder



          Guru

          Thanked: 139
        • Experience: Familiar
        • OS: Windows 10
        Re: Need to create a batchfile, which sends Alerts
        « Reply #9 on: February 19, 2007, 05:40:00 AM »
        Quote
        I've tested your script, but it's not working


        Please be specific, our resident mystic was run over by a truck. She never saw it coming ;D. Post your console output.

         8-)

        Actually I just copied a previous snippet from your thread and added the blat command.
        « Last Edit: February 19, 2007, 05:53:09 AM by Sidewinder »
        The true sign of intelligence is not knowledge but imagination.

        -- Albert Einstein

        Alok_Kumar

        • Guest
        Re: Need to create a batchfile, which sends Alerts
        « Reply #10 on: February 19, 2007, 09:36:49 PM »


        Once again thanks Winder, I did use the script, which I am pasting below on the board.

        @echo off
        set ip=110.110.6.5 110.110.6.4
        for /F  "tokens=1* delims= " %%i in ("%ip%") do (
              ping -n 2 %%i > nul
              if errorlevel 1 (
                      set msg=Ping failed: %%i
                     blat c:\emp.txt -to my_email_id -subject %msg%
                  )
        )

         
        I've saved the above script as batch file. When I double click it, command prompt screen comes up and disappers after a while, When I see my mail box, Diden't see any mail.
        I need your favour, could your explain me in brief that what is doing this script step by step? thanks, once again.

        hare krishna
        Alok


         




        Sidewinder



          Guru

          Thanked: 139
        • Experience: Familiar
        • OS: Windows 10
        Re: Need to create a batchfile, which sends Alerts
        « Reply #11 on: February 20, 2007, 05:13:50 AM »
        The file setups up a literal of two ip addresses separated by a space (the set statment). A loop is setup and each ip from the set statment is processed (the for statment). Each ip is pinged twice (the ping statment). Next the return code from the ping is checked (the if statment) and if it's 1 or greater (meaning the ping failed) then a message is set up and blat runs (the set and blat statments).

        When debugging a file, it helps to run from a command prompt (not double clicking from explorer) and removing echo off will let you see a blow by blow description of what is happening.

        For the record, I do not use blat on my machine, but the processor finds no syntax error in the file. For further assistance please post your console output.

         8-)
        The true sign of intelligence is not knowledge but imagination.

        -- Albert Einstein

        Alok_Kumar

        • Guest
        Re: Need to create a batchfile, which sends Alerts
        « Reply #12 on: February 20, 2007, 10:49:53 PM »
        Thanks Winder, Your help is really very helpfull to me, though I am not able to execute the last discussed codes, but still able to learn few things from you. I am pasting the code below, which I tried to run at command prompt.

        C:\>set ip=132.122.6.5 132.122.6.4

        C:\>for /F  "tokens=1* delims= " %%i in ("%ip%") do (
        %%i was unexpected at this time.

        C:\>50hr8_main.logping -n 2 %%i > nul
        '50hr8_main.logping' is not recognized as an internal or external command,
        operable program or batch file.

        C:\>50hr8_main.logif errorlevel 1 (
        '50hr8_main.logif' is not recognized as an internal or external command,
        operable program or batch file.

        C:\>              set msg=Ping failed: %%i

        C:\>             blat c:\emp.txt -to [email protected] -subject %msg%
        Blat v2.6.1 w/GSS encryption (build : Nov 18 2006 11:59:59)

        Blat saw and processed these options, and was confused by the last one...
            -to [email protected]
            -subject Ping
            failed:
        Do not understand argument: failed:

        Win32 console utility to send mail via SMTP or post to usenet via NNTP
        by P.Mendes,M.Neal,G.Vollant,T.Charron,T.Musson,H.Pesonen,A.Donchey,C.Hyde
          http://www.blat.net
        syntax:
          Blat <filename> -to <recipient> [optional switches (see below)]
          Blat -install <server addr> <sender's addr> [<try>[<port>[<profile>]]] [-q]
          Blat -profile [-delete | "<default>"] [profile1] [profileN] [-q]
          Blat -h

        hare krishna
        Alok

        gpl



          Apprentice
        • Thanked: 27
          Re: Need to create a batchfile, which sends Alerts
          « Reply #13 on: February 21, 2007, 03:09:24 AM »
          I cannot comment about the rest of your code, but the reason the first error came up is due to the way the command processor works .... when in a batch file, %% always resolves to a single %

          to run at the command prompt, your command should use single % thus
          for /F  "tokens=1* delims= " %i in ("%ip%") do (

          and then reference %i later on

          This might remove later errors
          Graham

          Alok_Kumar

          • Guest
          Re: Need to create a batchfile, which sends Alerts
          « Reply #14 on: February 21, 2007, 03:25:08 AM »

          Thanks Gpl, Well I really not able to achive for which I did a post. Well, I would again like to discuss my problem.I just need to creata a batch file, which should ping to some machine and if it gets failed then it should mailed back to me , stating the ping gets failed. If you have any working procedure, then do let me know of those, As I really need to achive the above discussed logic as soon as possible. Thanks, once again.

          hare krishna
          Alok