cromertech Posted June 21, 2011 Posted June 21, 2011 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 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
Steve21 Posted June 21, 2011 Posted June 21, 2011 (edited) 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: @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 Steve Edited June 21, 2011 by Steve21
andy_b Posted June 21, 2011 Posted June 21, 2011 Another variant: @echo off set ipaddr=XXXX PING -n 1 -w 7500 %ipaddr% | find "TTL=" || goto fail :pass echo goto eof :fail echo :eof
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now