Computing.Net > Forums > Programming > DOS batch help (ipconfig | find)

DOS batch help (ipconfig | find)

Reply to Message Icon

Original Message
Name: benhart007
Date: January 24, 2006 at 16:34:24 Pacific
Subject: DOS batch help (ipconfig | find)
OS: XP Pro SP2
CPU/Ram: Athlon 1700
Comment:

Im trying to create a batch file to reset different portions of the TCP/IP stack. But I want to base the errorlevel of each command off of specific keywords in the output of each command, such as:

ipconfig /flushdns | find /I "failed"

Now I've got a batch created at work that runs:
ipconfig /flushdns
ipconfig /registerdns
nbtstat -RR

Now when I run this batch I see the output of each command as if I ran them seperately and sometimes the /registerdns will fail if you attempt to run it more than once per two minutes. I want the :Error cooresponding to this command to be called if the text output contains the word "failed". I have tried my example above like:
ipconfig /flushdns | find /I "failed"
but when I run the batch each and every command calls the errorlevel 1 goto Error(number). Like this:

@echo off
ipconfig /flushdns | find /I "failed"
errorlevel 1 goto Error1
echo Ipconfig flushed
echo off

ipconfig /registerdns | find /I "failed"
errorlevel 1 goto Error2
echo Ipconfig registered DNS names
echo off

nbtstat -RR
errorlevel 1 goto Error3
echo Netbios cache flushed
echo off

Is there anyway that I can do this? Even if it's piping the screen output to a %TEMP%\name.txt file then pulling from there...I just cannot figure it out.

Thanks!


Report Offensive Message For Removal


Response Number 1
Name: Mechanix2Go
Date: January 24, 2006 at 22:41:27 Pacific
Reply: (edit)

Hi ben,

I think you're pretty close.

FIND sets errorlevel 1 if the string is NOT found. So instead of this:

ipconfig /flushdns | find /I "failed"
errorlevel 1 goto Error1

I think you need:

ipconfig /flushdns | find /I "failed"
if not errorlevel 1 goto Error1

Which means the string "failed" WAS FOUND.

Make sense?

BTW, you can save some typing and some clutter by eliminating all 'echo off' but the first one. Once it's off, it's off.

HTH


If at first you don't succeed, you're about average.

M2


Report Offensive Follow Up For Removal

Response Number 2
Name: benhart007
Date: January 25, 2006 at 06:24:41 Pacific
Reply: (edit)

Ok cool, yeah I beileve that resolved the first half of my batch.... now last question:

towards teh bottom after the TCP/IP stack has been flushed/refreshed, I have the batch ping our router. What I wanted to do was if "TTL=" then errorlevel 1 goto Error6, like the above lines.

ping xxx.xxx.xxx.xxx | find "TTL=" >NUL
if errorlevel 1 goto Error6
echo Ping'd Successfully
echo off

Now Error6 just changes the color to 04 and echos Gateway Ping Failed.

Did I use the correct syntax above for this to work? If TTL is = to NUL, then goto Error6?


Report Offensive Follow Up For Removal

Response Number 3
Name: Mechanix2Go
Date: January 25, 2006 at 22:49:45 Pacific
Reply: (edit)

"ping xxx.xxx.xxx.xxx | find "TTL=" >NUL
if errorlevel 1 goto Error6
echo Ping'd Successfully"

Im a little confused. Those three lines look OK.

My confusion is with this phrase:

"f TTL is = to NUL, then goto Error6"



If at first you don't succeed, you're about average.

M2


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: DOS batch help (ipconfig | find)

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software




Have you ever used OpenOffice?

Yes, as my main suite.
Yes, occationally.
Yes, but only once.
No, never.


View Results

Poll Finishes In 5 Days.
Discuss in The Lounge