7.07.2010

Neat PING BAT file


Comment: I'm troubleshooting why we were unable to remotely upgrade several hundred computers. I had been manually pinging each one ... like this

PING WFC1A000AE0C975

I decided to write a BAT file to do the work. Well someone had done this for me.

here

With this as the basis:

The BAT FILE:

@echo off

(Set InputFile=C:\temporary\list.txt)

title,Pinging list of computers &color 9e

::datestamp
for /f "tokens=2-4 skip=1 delims=(-./)" %%i in ('echo.^|date') do (
for /f "tokens=1-4 delims=-./ " %%m in ('date /t') do (
(set dow=%%m)&(set %%i=%%n)&(set %%j=%%o)&(set yy=%%p) ) )
For /F "tokens=1,2 delims=:, " %%i in ('TIME /T') Do (Set HHMM=%%i%%j)

(Set OutputFile=c:\temporary\Pinglog %yy%-%mm%-%dd% %HHMM%.txt)

If Exist "%OutputFile%" Del "%OutputFile%"


For /F "usebackq eol=;" %%* In ("%InputFile%") Do (
Ping.exe -n 2 -w 750 %%* | Find/i "TTL=" >Nul && (
echo.%%* "was PINGABLE">>"%OutputFile%")|| (
echo.%%* "was NOT pingable">>"%OutputFile%")
echo.done %%*,)


The input file (computer names changed!):

WFC1A000AE0C975
WFCPTXWLRESBOX5
WFCPTXWLH39MXC1
WFCPTXWLDN6MXC1
WFC2300D74C069C
WFCPTXWLF43MXC1
WFCPTXWL7RFMXC1
WFCPTXWL5L8MXC1
WFCPTXWLTRAIN19
WFCPTXWL979MXC1
WFCPTXWLRESBOX4
WFCPTXWL363MXC1
WFC120097EAA8AB
WFCPTXWL3P8MXC1
WFCPTXWL8JP9YF1


The output file:

WFC1A000AE0C975 "was NOT pingable"
WFCPTXWLRESBOX5 "was NOT pingable"
WFCPTXWLH39MXC1 "was NOT pingable"
WFCPTXWLDN6MXC1 "was NOT pingable"
WFC2300D74C069C "was PINGABLE"
WFCPTXWLF43MXC1 "was NOT pingable"
WFCPTXWL7RFMXC1 "was NOT pingable"
WFCPTXWL5L8MXC1 "was NOT pingable"
WFCPTXWLTRAIN19 "was NOT pingable"
WFCPTXWL979MXC1 "was NOT pingable"
WFCPTXWLRESBOX4 "was NOT pingable"
WFCPTXWL363MXC1 "was NOT pingable"
WFC120097EAA8AB "was NOT pingable"
WFCPTXWL3P8MXC1 "was NOT pingable"
WFCPTXWL8JP9YF1 "was NOT pingable"

4 comments:

  1. Enhanced as comma delimited output

    @echo off

    (Set InputFile=C:\temporary\list.txt)

    title,Pinging list of computers &color 9e

    ::datestamp
    for /f "tokens=2-4 skip=1 delims=(-./)" %%i in ('echo.^|date') do (
    for /f "tokens=1-4 delims=-./ " %%m in ('date /t') do (
    (set dow=%%m)&(set %%i=%%n)&(set %%j=%%o)&(set yy=%%p) ) )
    For /F "tokens=1,2 delims=:, " %%i in ('TIME /T') Do (Set HHMM=%%i%%j)

    (Set OutputFile=c:\temporary\Pinglog %yy%-%mm%-%dd% %HHMM%.csv)

    If Exist "%OutputFile%" Del "%OutputFile%"


    For /F "usebackq eol=;" %%* In ("%InputFile%") Do (
    Ping.exe -n 2 -w 750 %%* | Find/i "TTL=" >Nul && (
    echo "%%*","was PINGABLE">>"%OutputFile%")|| (
    echo "%%*","was NOT pingable">>"%OutputFile%")
    echo.done %%*,)

    ReplyDelete
  2. When I left work at 5:20 ... I set my batch file to ping 900+ workstations.

    Will try again tomorrow at noon. You would think they would be on-line mid day

    ReplyDelete
  3. I ran it again today against 1197 workstations. 657 did not respond to the ping

    ReplyDelete

Any anonymous comments with links will be rejected. Please do not comment off-topic