+ Post New Thread
Results 1 to 3 of 3
Scripts Thread, Batch file needed please in Coding and Web Development; I'm trying to write a batch file to do a series of tasks when a ping fails so far I ...
  1. #1
    cromertech's Avatar
    Join Date
    Dec 2007
    Cromer by the coast
    Thank Post
    Thanked 109 Times in 97 Posts
    Rep Power

    Question Batch file needed please

    I'm trying to write a batch file to do a series of tasks when a ping fails so far I have the following but I'm unsure of the syntax and how to get mutiple lines into the if statement
    @echo off
    set ipaddr=
    set state=down
    for /f "tokens=5,7" %%a in (ping -n 1 !ipaddr!') do (
    if "x%%a"=="xReceived" if "x%%b"=="x1," set state=up
    if state=up goto :eof
    {something in here for ping fail}
    Does this sort of look ok or is there maybe an easier way

  2. #2

    Steve21's Avatar
    Join Date
    Feb 2011
    Thank Post
    Thanked 544 Times in 507 Posts
    Rep Power
    Well I can't run BAT files here to test it, but from a quick glance looks like a far bit of that you don't need really.

    state=down/up doesn't nothing, unless you're using it later in the script. You might aswell just replace set state-up with a goto:

    Don't really need setlocal as it's just declaring local vars, and with that script it doesn't really matter either way.


    More like this:

    @echo  off
    set ipaddr=XXX
    for PING) do (
    if NOT A if NOT B goto fail
    goto pass
    Amg it passed
    Amg it failed
    Aka it checks if it's not valid, if not it'll jump to fail, else it'll run passed. (Or nothing if it's only to check fail)

    Only an idea :P

    Last edited by Steve21; 21st June 2011 at 12:27 PM.

  3. #3

    Join Date
    Apr 2007
    Thank Post
    Thanked 45 Times in 39 Posts
    Rep Power
    Another variant:

    @echo  off
    set ipaddr=XXXX
    PING -n 1 -w 7500 %ipaddr% | find "TTL=" || goto fail 
    echo :)
    goto eof
    echo :(

+ Post New Thread

Similar Threads

  1. For Next Loop in Batch File
    By barrystone in forum Scripts
    Replies: 2
    Last Post: 17th March 2011, 02:10 PM
  2. Batch File Needed??- Profile Problem
    By Techdw in forum Windows
    Replies: 24
    Last Post: 26th May 2010, 11:22 AM
  3. Batch File (select random file) help
    By fil_b in forum Windows Server 2000/2003
    Replies: 5
    Last Post: 5th November 2009, 05:13 AM
  4. batch to bash rewrite help needed please
    By RabbieBurns in forum Scripts
    Replies: 4
    Last Post: 22nd September 2008, 10:05 AM
  5. batch file help
    By beeswax in forum Scripts
    Replies: 9
    Last Post: 3rd March 2006, 08:48 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts