2016-05-26 3 views
0

Ich möchte mein Skript ausführen und eine Protokolldatei erstellen. was es macht. Ich möchte dieses Skript ein zweites Mal ausführen und an dieselbe Protokolldatei anhängen, aber ich möchte, dass es in eine neue Spalte geht. Erleichtern Sie es, die beiden Ergebnisse nebeneinander zu vergleichen. Unten ist mein Skript so weit. Vielen Dank im Voraus.An ein vorhandenes Batchdateiprotokoll anfügen, aber an eine andere Spalte mit derselben Batchdatei

echo off 
color a 
cls 
@echo Welcome to the Ping Scan CheckList Script v2 
echo. 
@echo This script is going to expect three octets, and test the fourth. 
@echo You can break the store i.p. into 4 octets. I.E. 10.x.yy.zz where x and yy equal the store number. 
@echo Please begin entering the first three now. 
ECHO. 
SET/p first=First Octet: 
SET/p second=Second Octet: 
SET/p third=Third Octet: 
@ECHO %DATE% %TIME% >>%USERPROFILE%\DESKTOP\%second%%third%-%USERNAME%-%DATE:~4,2%%DATE:~7,2%%DATE:~10,4%.csv 
SET t=0 
:start 
SET /a t=t+1 
if %t%==2 GoTo start 
if %t%==4 GoTo start 
if %t%==15 GoTo start 
if %t%==18 GoTo start 
if %t%==19 GoTo start 
if %t%==34 GoTo start 
if %t%==43 GoTo start 
if %t%==44 GoTo start 
if %t%==45 GoTo start 
if %t%==47 GoTo start 
if %t%==48 GoTo start 
if %t%==55 GoTo start 
if %t%==59 GoTo start 
if %t%==61 GoTo start 
if %t%==64 GoTo start 
if %t%==67 GoTo start 
if %t%==69 GoTo start 
if %t%==73 GoTo start 
if %t%==74 GoTo start 
if %t%==87 GoTo start 
if %t%==89 GoTo start 
if %t%==98 GoTo start 
if %t%==99 GoTo start 
if %t%==100 GoTo start 
if %t%==101 GoTo start 
if %t%==102 GoTo start 
if %t%==103 GoTo start 
if %t%==104 GoTo start 
if %t%==105 GoTo start 
if %t%==106 GoTo start 
if %t%==107 GoTo start 
if %t%==108 GoTo start 
if %t%==109 GoTo start 
if %t%==110 GoTo start 
if %t%==111 GoTo start 
if %t%==112 GoTo start 
if %t%==113 GoTo start 
if %t%==114 GoTo start 
if %t%==115 GoTo start 
if %t%==116 GoTo start 
if %t%==117 GoTo start 
if %t%==118 GoTo start 
if %t%==119 GoTo start 
if %t%==120 GoTo start 
if %t%==121 GoTo start 
if %t%==122 GoTo start 
if %t%==123 GoTo start 
if %t%==124 GoTo start 
if %t%==125 GoTo start 
if %t%==126 GoTo start 
if %t%==127 GoTo start 
if %t%==128 GoTo start 
if %t%==132 GoTo start 
if %t%==133 GoTo start 
if %t%==134 GoTo start 
if %t%==158 GoTo start 
if %t%==159 GoTo start 
if %t%==166 GoTo start 
if %t%==170 GoTo start 
if %t%==179 GoTo start 
if %t%==185 GoTo start 
if %t%==191 GoTo start 
if %t%==192 GoTo start 
if %t%==194 GoTo start 
if %t%==195 GoTo start 
if %t%==198 GoTo start 
if %t%==199 GoTo start 
if %t%==202 GoTo start 
if %t%==203 GoTo start 
if %t%==204 GoTo start 
if %t%==207 GoTo start 
if %t%==208 GoTo start 
if %t%==209 GoTo start 
if %t%==212 GoTo start 
if %t%==213 GoTo start 
if %t%==214 GoTo start 
echo Pinging .%t% 
ping -w 100 -l 1 %first%.%second%.%third%.%t% > nul 
if %errorlevel%==0 echo %first%.%second%.%third%.%t% is UP! >> %USERPROFILE%\DESKTOP\%second%%third%-%USERNAME%-%DATE:~4,2%%DATE:~7,2%%DATE:~10,4%.csv 
if %errorlevel%==1 echo ****%first%.%second%.%third%.%t%**** is DOWN! >> %USERPROFILE%\DESKTOP\%second%%third%-%USERNAME%-%DATE:~4,2%%DATE:~7,2%%DATE:~10,4%.csv 
IF %t%==217 GoTo finish 
Goto start 
:finish 
@echo The script is done, you can find the full log on your desktop 
pause 

Antwort

0

zunächst eine Liste mit den gewünschten IP`s (letzte Oktett) bauen, wie folgt aus:

IP 
1 
3 
5 
6 
7 
8 
9 
10 
11 
12 
13 
14 
16 
(and so on) 

als Basis für den folgenden Code:

@echo off 
setlocal enabledelayedexpansion 
break>b.csv 
set "base=192.168.178" 
for /f "tokens=1,*delims=," %%i in (a.csv) do (
if "%%i"=="IP" (
    echo %%i,%%j,%time:~0,5%>>b.csv 
) else (
    ping -n 1 -w 100 -4 %base%.%%i|find "TTL=" >nul && set "state=UP" || set "state=DOWN" 
    echo %%i,%%j,!state!>>b.csv 
) 
) 
type b.csv>a.csv 
type a.csv 

I verkürzt die Dateinamen und Zeichenfolgen, um den Code lesbar zu halten.

Es gibt ein kleines Problem mit der ersten Iteration (zwei aufeinanderfolgende Kommas), das mit einem anderen if korrigiert werden könnte - aber es ist "selbstkorrigierend" mit der nächsten Iteration.

Hinweis: Der Errorlevel von ping ist nicht zuverlässig, daher sollten Sie nach "TTL =" suchen.

Verwandte Themen