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

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

DOS batch help (ipconfig | find)

Reply to Message Icon

Name: benhart007
Date: January 24, 2006 at 16:34:24 Pacific
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!



Sponsored Link
Ads by Google

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

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


0

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

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?


0

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

"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


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: DOS batch help (ipconfig | find)

help on creating DOS Batch file www.computing.net/answers/programming/help-on-creating-dos-batch-file/15163.html

MS Dos batch Script Help www.computing.net/answers/programming/ms-dos-batch-script-help/14592.html

DOS Batch help needed www.computing.net/answers/programming/dos-batch-help-needed/18973.html