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