Computing.Net > Forums > Disk Operating System > Find command

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.

Find command

Reply to Message Icon

Name: lee
Date: February 27, 2001 at 03:32:15 Pacific
Comment:

Hi
I can ping xyz >> ping.txt to dump the contents into the file. I then want to query this file for a successfull ping and if so map a drive to that machine. Can someone tell me how to do this. I have tried to use the find command but cannot get it to generate an error level so it can progress.

Thanks in advance

Lee



Sponsored Link
Ads by Google

Response Number 1
Name: Laurence
Date: February 27, 2001 at 05:33:24 Pacific
Reply:

Find returns errorlevels 0, 1, 2


Try these, but WATCH for wrapped lines!

:: pingnow.bat
@ECHO off
IF "%1"=="" ECHO IP address required
IF "%1"=="" GOTO end
:: Ascii assembler code by Herbert Kleebauer
ECHO
,8P_,FPZ0U]0U[,B0EWP_[SCYQ2M@I~E5@@O!A>%temp%.\echoit.com
TYPE nul >%temp%.\log.txt
SET cnt=

:loop
SET cnt=%cnt%*
ECHO @PROMPT SET time=$t> %temp%.\gettim1.bat
%COMSPEC% /E:2048 /c %temp%.\gettim1.bat>
%temp%.\gettim2.bat
CALL %temp%.\gettim2.bat

%temp%.\echoit.com %time% >>%temp%.\log.txt
PING -a -n 1 -s 1 %1 |FIND "Re" >>%temp%.\log.txt
IF errorlevel 1 ECHO Destination not reachable
IF not "%cnt%"=="*****" GOTO loop
SET cnt=
SET time=
DEL %temp%.\gettim2.bat
DEL %temp%.\echoit.com
TYPE %temp%.\log.txt
:end
::

:: pingnow2.bat
@ECHO off
IF "%1"=="" ECHO IP address required
IF "%1"=="" GOTO end
:: Ascii assembler code by Herbert Kleebauer
PING -a -n 1 -s 1 %1 |FIND "Re" >nul
IF errorlevel 1 ECHO Destination not reachable
IF errorlevel 1 GOTO end
SET cnt=
TYPE nul >%temp%.\log.txt
TYPE nul >%temp%.\log.tmp
ECHO
,8P_,FPZ0U]0U[,B0EWP_[SCYQ2M@I~E5@@O!A>%temp%.\echoit.com
ECHO * * Press Q to quit * *

:loop
SET cnt=%cnt%*
ECHO @PROMPT SET time=$t>%temp%.\gettim1.bat
%COMSPEC% /E:2048 /c %temp%.\gettim1.bat>
%temp%.\gettim2.bat
CALL %temp%.\gettim2.bat
%temp%.\echoit.com %time% > %temp%.\log.tmp
PING -a -n 1 -s 1 %1 |FIND "Re">> %temp%.\log.tmp
TYPE %temp%.\log.tmp >>%temp%.\log.txt

TYPE %temp%.\log.tmp
IF "%cnt%"=="***********************" ECHO * *
Press Q to quit * *
IF "%cnt%"=="***********************" SET cnt=
CHOICE.COM /N /CQC /TC,1 >nul
IF errorlevel 2 GOTO loop
SET cnt=
SET time=
DEL %temp%.\gettim?.bat
DEL %temp%.\echoit.com
:end
::

Batfiles: The DOS batch file programming handbook


0

Response Number 2
Name: Lee
Date: February 27, 2001 at 06:53:35 Pacific
Reply:

Thanks for that.

So is there an easy way??

Lee


0

Response Number 3
Name: hmpxrii
Date: February 27, 2001 at 09:42:07 Pacific
Reply:

Truely, my dear friend, that was a disgusting display of batch. I would do it this way:

@echo off
ping xyz>ping.txt
find "oåtkomlig" ping.txt>nul
if errorlevel 1 goto reachable

echo Could not ping!
goto end
:reachable

echo Could ping!
:end

note 1: I am unsure about how to map network drives for the moment. Replace the line "echo Could ping!" with whatever command is needed to map the network drive.
note 2: you shall also, of course, replaze "xyz" with the ip/name of the computer you are pinging.
note 3: the string "oåtkomlig" means unreachable in Swedish, which happens to be the language of my operating system. I think the English/American version of ping says "unreachable", but I am not sure about the exact words and such so you just replace "oåtkomlig" with any string that ping only outputs when it can't ping the computer.
Good luck.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


how to copy partition tab... Ms dos



Post Locked

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


Go to Disk Operating System Forum Home


Sponsored links

Ads by Google


Results for: Find command

The FIND command www.computing.net/answers/dos/the-find-command/13233.html

I Need Help with the FIND Command www.computing.net/answers/dos/i-need-help-with-the-find-command/12687.html

DOS Help with Find command www.computing.net/answers/dos/dos-help-with-find-command/13555.html