+ 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
    Location
    Cromer by the coast
    Posts
    731
    Thank Post
    177
    Thanked 109 Times in 97 Posts
    Rep Power
    54

    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
    Code:
    @echo off
    setlocal
    set ipaddr=10.90.11.103
    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}
    
    :eof
    Does this sort of look ok or is there maybe an easier way

  2. #2

    Steve21's Avatar
    Join Date
    Feb 2011
    Location
    Swindon
    Posts
    2,686
    Thank Post
    334
    Thanked 513 Times in 481 Posts
    Rep Power
    178
    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.

    Steve

    More like this:

    Code:
    @echo  off
    set ipaddr=XXX
    for PING) do (
    if NOT A if NOT B goto fail
    goto pass
    
    :pass
    Amg it passed
    
    :fail
    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

    Steve
    Last edited by Steve21; 21st June 2011 at 11:27 AM.

  3. #3

    Join Date
    Apr 2007
    Location
    Birmingham
    Posts
    142
    Thank Post
    6
    Thanked 45 Times in 39 Posts
    Rep Power
    22
    Another variant:

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

SHARE:
+ Post New Thread

Similar Threads

  1. For Next Loop in Batch File
    By barrystone in forum Scripts
    Replies: 2
    Last Post: 17th March 2011, 01:10 PM
  2. Batch File Needed??- Profile Problem
    By Techdw in forum Windows
    Replies: 24
    Last Post: 26th May 2010, 10: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, 04:13 AM
  4. batch to bash rewrite help needed please
    By RabbieBurns in forum Scripts
    Replies: 4
    Last Post: 22nd September 2008, 09:05 AM
  5. batch file help
    By beeswax in forum Scripts
    Replies: 9
    Last Post: 3rd March 2006, 07: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
  •