bat to export results to 2nd column.

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
smarkcum0412
Posts: 10
Joined: 22 Jun 2016 12:42

bat to export results to 2nd column.

#1 Post by smarkcum0412 » 22 Jun 2016 12:58

Hello all Thanks for looking,,

I have a script that I put together and it works great. I want to add to it. I want the first column to be router (which i have working). I want the 2nd column to be a variable Ip that pings +1 everytime and I want the output of that to go to the 2nd column (column b).

See Script below..

Code: Select all

echo off
color a
cls
@echo Welcome to the Ping Scan CheckList Script v3
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:
set dat=%USERPROFILE%\DESKTOP\%second%%third%-%USERNAME%-%DATE:~4,2%%DATE:~7,2%%DATE:~10,4%.csv
@echo !!!!! %DATE% %TIME% !!!!!,IP >>%USERPROFILE%\DESKTOP\%second%%third%-%USERNAME%-%DATE:~4,2%%DATE:~7,2%%DATE:~10,4%.csv
echo "Router">>%dat%
echo "Router">>%dat%
echo "Router">>%dat%
echo "Router">>%dat%
echo "Router">>%dat%
echo "Router">>%dat%
echo "Router">>%dat%
echo "Router">>%dat%
echo "Router">>%dat%
echo "Router">>%dat%
echo "Router">>%dat%
echo "Router">>%dat%
echo "Router">>%dat%
echo "Router">>%dat%
echo "Router">>%dat%
echo "Router">>%dat%
echo "Router">>%dat%
echo "Router">>%dat%
echo "Router">>%dat%
echo "Router">>%dat%
echo "Router">>%dat%
echo "Router">>%dat%
echo "Router">>%dat%
echo "Router">>%dat%
echo "Router">>%dat%
echo "Router">>%dat%
echo "Router">>%dat%
echo "Router">>%dat%
echo "Router">>%dat%
echo "Router">>%dat%
echo "Router">>%dat%
echo "Router">>%dat%
echo "Router">>%dat%
echo "Router">>%dat%
echo "Router">>%dat%
echo "Router">>%dat%
echo "Router">>%dat%
echo "Router">>%dat%
echo "Router">>%dat%
echo "Router">>%dat%
echo "Router">>%dat%
echo "Router">>%dat%
echo "Router">>%dat%
echo "Router">>%dat%
echo "Router">>%dat%
echo "Router">>%dat%
echo "Router">>%dat%
echo "Router">>%dat%
echo "Router">>%dat%
echo "Router">>%dat%
echo "Router">>%dat%
echo "Router">>%dat%
echo "Router">>%dat%
echo "Router">>%dat%
echo "Router">>%dat%
echo "Router">>%dat%
echo "Router">>%dat%
echo "Router">>%dat%
echo "Router">>%dat%
echo "Router">>%dat%
echo "Router">>%dat%
echo "Router">>%dat%
echo "Router">>%dat%
echo "Router">>%dat%
echo "Router">>%dat%
echo "Router">>%dat%
echo "Router">>%dat%
echo "Router">>%dat%
echo "Router">>%dat%
echo "Router">>%dat%
echo "Router">>%dat%
echo "Router">>%dat%
echo "Router">>%dat%
echo "Router">>%dat%
echo "Router">>%dat%
echo "Router">>%dat%
echo "Router">>%dat%
echo "Router">>%dat%
echo "Router">>%dat%
echo "Router">>%dat%
echo "Router">>%dat%
echo "Router">>%dat%
echo "Router">>%dat%
echo "Router">>%dat%
echo "Router">>%dat%
echo "Router">>%dat%
echo "Router">>%dat%
echo "Router">>%dat%
echo "Router">>%dat%
echo "Router">>%dat%
echo "Router">>%dat%
echo "Router">>%dat%
echo "Router">>%dat%
echo "Router">>%dat%
echo "Router">>%dat%
echo "Router">>%dat%
SET t=0
:start
SET /a t=t+1
echo Pinging .%t%
ping -w 200 -l 1 %first%.%second%.%third%.%t% > nul
if %errorlevel%==0 echo "",%first%.%second%.%third%.%t% is UP!>>%dat%
if %errorlevel%==1 echo "",****%first%.%second%.%third%.%t%**** is DOWN!>>%dat%

IF %t%==217 GoTo finish
Goto start
:finish
@echo The script is done, you can find the full log on your desktop
pause

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: bat to export results to 2nd column.

#2 Post by foxidrive » 22 Jun 2016 13:10

What do you see in your csv file at present

What is the purpose of so many of these lines?

Code: Select all

echo "Router">>%dat%

smarkcum0412
Posts: 10
Joined: 22 Jun 2016 12:42

Re: bat to export results to 2nd column.

#3 Post by smarkcum0412 » 22 Jun 2016 13:23

I am going to have different names in there eventually to replace "router"

below is a copy of the csv output.

Code: Select all

!!!!! Wed 06/22/2016 14:13:55.88 !!!!!   IP 
Router   
Router   
Router   
Router   
Router   
Router   
Router   
Router   
Router   
Router   
Router   
Router   
Router   
Router   
Router   
Router   
Router   
Router   
Router   
Router   
Router   
Router   
Router   
Router   
Router   
Router   
Router   
Router   
Router   
Router   
Router   
Router   
Router   
Router   
Router   
Router   
Router   
Router   
Router   
Router   
Router   
Router   
Router   
Router   
Router   
Router   
Router   
Router   
Router   
Router   
Router   
Router   
Router   
Router   
Router   
Router   
Router   
Router   
Router   
Router   
Router   
Router   
Router   
Router   
Router   
Router   
Router   
Router   
Router   
Router   
Router   
Router   
Router   
Router   
Router   
Router   
Router   
Router   
Router   
Router   
Router   
Router   
Router   
Router   
Router   
Router   
Router   
Router   
Router   
Router   
Router   
Router   
Router   
Router   
Router   
Router   
                          B10.3.3.1 is UP!
                          B10.3.3.2 is UP!
                          B10.3.3.3 is UP!

Column A shows "router" column B "10.... is up" but is starts on the row after the last router. I need it to start in row 1 column B.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: bat to export results to 2nd column.

#4 Post by foxidrive » 22 Jun 2016 13:33

Paste a listing of how you would like to see it.

smarkcum0412
Posts: 10
Joined: 22 Jun 2016 12:42

Re: bat to export results to 2nd column.

#5 Post by smarkcum0412 » 22 Jun 2016 13:40

Code: Select all

column A                                         Column B
!!!!! Wed 06/22/2016 14:39:45.88 !!!!!

router                                              10.3.3.1 is UP
router                                              10.3.3.2 is UP
router                                              10.3.3.3 is UP
router                                              10.3.3.4 is DOWN



the formatting gets messed up when i post it


if you run the script you can see the output on ur desktop. enter in the first 3 octets of ur local ip and let it run a few pings then kill it and look at the results. I need "10.x.x.x is UP"/10.x.x.x is DOWN to start in row 1 column B.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: bat to export results to 2nd column.

#6 Post by foxidrive » 22 Jun 2016 20:43

smarkcum0412 wrote:the formatting gets messed up when i post it


I added code tags around your text to correct the formatting as you posted it, and they use BBcode - check your forum settings to see if BBcode has been disabled.



I see the way your text is formatted is not a .csv format that you originally mentioned. Can you comment on this aspect?

I'm asking questions to clarify your aim, so that any code you are provided with can be accurate and doesn't have to re-written due to misunderstandings.

smarkcum0412
Posts: 10
Joined: 22 Jun 2016 12:42

Re: bat to export results to 2nd column.

#7 Post by smarkcum0412 » 23 Jun 2016 05:56

after the bat file runs it creates a .cvs file on the desktop. Which is what I want. the problem is I need "router" to start in row 2 column a of that cvs file. Which it does. I need "x.x.x.x is UP" to start in row 2 column B and it does not.

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: bat to export results to 2nd column.

#8 Post by Squashman » 23 Jun 2016 07:49

I am really not understanding why you would output the word ROUTER to the log file before you ping and get the results. Just output the word ROUTER and all the variables after you get the ping results back.

smarkcum0412
Posts: 10
Joined: 22 Jun 2016 12:42

Re: bat to export results to 2nd column.

#9 Post by smarkcum0412 » 23 Jun 2016 07:59

i think you are missing the point. Don't concentrate on "router" that is not the issue.

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: bat to export results to 2nd column.

#10 Post by Squashman » 23 Jun 2016 08:31

smarkcum0412 wrote:i think you are missing the point. Don't concentrate on "router" that is not the issue.

Nope. I am not. I think you are not understanding that you are trying to accomplish this incorrectly. You seem to think you can append a second column of information to your existing text file in a specific spot on each line just by simply using the append command. That cannot be done without reading the existing file first, line by line. Also, none of your output examples show any commas yet we see it in your code.

smarkcum0412
Posts: 10
Joined: 22 Jun 2016 12:42

Re: bat to export results to 2nd column.

#11 Post by smarkcum0412 » 23 Jun 2016 08:45

now we are getting somewhere. I may be trying to accomplish this incorrectly. That is why I came to a forum. the code shows the commas here

Code: Select all

if %errorlevel%==0 echo "",%first%.%second%.%third%.%t% is UP!>>%dat%
if %errorlevel%==1 echo "",****%first%.%second%.%third%.%t%**** is DOWN!>>%dat%


that is so the ip results "up or down" will go to the column b in the csv file. that part works like it should the only problem with it is that it will not start on row 1. It starts on row xx after all the "routers" have posted to the file in column A. Each one of the "router" will have a different name in the future and each item (router) has a different Ip associated with it. Right now the name "router" is just a place holder. Hope this helps answer your questions.

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: bat to export results to 2nd column.

#12 Post by Squashman » 23 Jun 2016 09:27

Well the other issue I have with your code is that you are pinging up to 217 but you do not have 217 router entries in your output file. You keep talking about the word ROUTER being a place holder. Why don't you explain to us what your end game is? Because if you change it later on the code could completely change.

smarkcum0412
Posts: 10
Joined: 22 Jun 2016 12:42

Re: bat to export results to 2nd column.

#13 Post by smarkcum0412 » 23 Jun 2016 10:06

Well I stopped adding those lines because it was not working the way I wanted it to work. so those line will have:
Router
New Top Tech
Managed Switch 1
Managed Switch 2
Managed Switch (Tire Shop)
Managed Switch 3
RFID Canopy Switch
TirePass Ethernet Switch
Wireless Access Point (WAP) 1
Wireless Access Point (WAP) 2
Tireshop WAP - Aruba 1
Tireshop WAP - Aruba 2
TS Wireless Access Point (Store)
TS Wireless Access Station (TS)
DSL All in One Printer (Fax Machine)
Lexmark Label Printer
Reserved - Digital Signage 1
Reserved - Digital Signage 2
Reserved - Digital Signage 3
Reserved - Digital Signage 4
Reserved - Digital Signage 5
Reserved - Digital Signage 6
Reserved - Digital Signage 7
Reserved - Digital Signage 8
Drive-Thru Timer
Hyperactive OCB
RTI Oil Filer (Food Svc)
Subway OMS (order management system)
Adaptive LED Sign/Flying J Sign
Lighting Monitor-205
Subway DT Kiosk
Subway DT Printer #1
Subway DT Printer #2
DVR - Store
DVR - Diesel
DVR - Tire Shop
Laundry CC Machines
Veeder Root
Veeder Root 1
Veeder Root 2
Junge - Blender Unit
Junge - Entry Screen
Junge - Printer
Economy Cntrls Bio Blend
Economy Cntrls Bio Blend #2
Economy Cntrls Bio Blend #3
CBT Computer 1
DAS Displays\ EEC
Subway Gift Card Terminal
Loyalty Kiosk
Mobile 2 Go Display
Transflo 1
Transflo 2
Mr. Payroll/ Western Union
CAT Scales 1
CAT Scales 2
CNG Monitoring Equipment
Cash Recycler
FlintLoc
Warren Rogers
HVAC - GridPoint
HVAC - Gilbarco Wisdom
Vintech System
TirePass Fuel Desk Comp
APC/UPS Non-Secure
TirePass Receipt Printer
OPTO22 Panel - Voltage
Laser Printer - Fuel Desk
TirePass PC Controller
TirePass Inflator Switch 1
TirePass Inflator Switch 2
TirePass Inflator Switch 3
TirePass Inflator Switch 4
TirePass Handheld 1 (Only if there is an Apon lane 17)
TirePass Handheld 2 (Only if there is an Apon lane 17)
Router
Load Balance NIC 1&2
iDRAC (Server)
KACE
KACE DHCP Reserve 1
KACE DHCP Reserve 2
KACE DHCP Reserve 3
KACE DHCP Reserve 4
Store Back Office
POS #1
POS #2
POS #3
POS #4
POS #5
POS #6
POS #7
POS #8
POS #9
Rest. Back Office
Rest. POS #1
Rest. POS #2
Rest. POS #3
Rest. POS #4
Rest. POS #5
Rest. POS #6
RBOS #2
FCC 1
Rest. Kitchen Video #1
Rest. Kitchen Video #2
Rest. Kitchen Video #3
Rest. Kitchen Video #4
Rest. Kitchen Video #5
NexGen 1
NexGen 2
FCC 2
Verifone - Diesel Desk
Verifone - Gas Desk
Verifone - Food
Verifone - Tire Shop
Verifone - Xpient Counter
MWS 1 (M1)
MWS 2 (M2 or AA Station)
Rest. MWS Standalone
RFID Reader 1
RFID Reader 2
RFID Reader 3
RFID Reader 4
RFID Reader 5
Car Wash Pedestals 2
Storage MWS 1 (U1)
Storage MWS 1 (U2)
Wireless Routers (Sagenet)
Wireless Routers (Sagenet)
Tire Shop Router
Tire Shop WAP #1 - Cisco
Tire Shop WAP #2 - Cisco
Tire Shop Computer 1
Tire Shop Computer 2
Tire Shop Maddenco/CBT
Tire Shop CBT
Laser Printer - Tire Shop 1
Laser Printer - Tire Shop 2
Tire Shop Noregon PC
Tire Shop Noregon DLA
Tire Shop Noregon PC (2nd Connection)

I just never got that far just in case it was not going to work the way i wanted it. To save time I stopped putting that info in and starting working with the issue. What i wanted the output log file to be was .csv with column A to have these names and column b to start at row 2 and have "x.x.x.x is UP or Down" so the ip corresponds with the correct hardware item.

This may or may not be relevant. I thought about getting the hardware name from each item as it pinged but networking tells me not everything we have is setup to respond to those type of requests.

I want to thank you for hashing this out with me. it would be great if i can get this to work.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: bat to export results to 2nd column.

#14 Post by foxidrive » 23 Jun 2016 13:28

Test this to see how it works for you.

Code: Select all

@echo off
color a
cls
echo Welcome to the Ping Scan CheckList Script v4
echo.
echo This script is going to expect three octets, and tests the fourth.
echo.
set "three_octets="
SET /p "three_octets=Please enter the first three octets (EG: 192.168.1) : "
if not defined three_octets goto :EOF
for /f "tokens=1-3 delims=." %%a in ("%three_octets%") do if "%%c"=="" echo try again & timeout 5 & %0

for /f "tokens=1-3 delims=." %%a in ("%three_octets%") do (
   set "dat=%USERPROFILE%\DESKTOP\%%b%%c-%USERNAME%-%DATE:~4,2%%DATE:~7,2%%DATE:~10,4%.csv"
)
echo !!!!! %DATE% %TIME% !!!!!,IP>"%dat%"


      for %%d in (
"New Top Tech"
"Managed Switch 1"
"Managed Switch 2"
"Managed Switch (Tire Shop)"
"Managed Switch 3"
"RFID Canopy Switch"
"TirePass Ethernet Switch"
"Wireless Access Point (WAP) 1"
"Wireless Access Point (WAP) 2"
"Tireshop WAP - Aruba 1"
"Tireshop WAP - Aruba 2"
"TS Wireless Access Point (Store)"
"TS Wireless Access Station (TS)"
"DSL All in One Printer (Fax Machine)"
"Lexmark Label Printer"
"Reserved - Digital Signage 1"
"Reserved - Digital Signage 2"
"Reserved - Digital Signage 3"
"Reserved - Digital Signage 4"
"Reserved - Digital Signage 5"
"Reserved - Digital Signage 6"
"Reserved - Digital Signage 7"
"Reserved - Digital Signage 8"
"Drive-Thru Timer"
"Hyperactive OCB"
"RTI Oil Filer (Food Svc)"
"Subway OMS (order management system)"
"Adaptive LED Sign/Flying J Sign"
"Lighting Monitor-205"
"Subway DT Kiosk"
"Subway DT Printer #1"
"Subway DT Printer #2"
"DVR - Store"
"DVR - Diesel"
"DVR - Tire Shop"
"Laundry CC Machines"
"Veeder Root"
"Veeder Root 1"
"Veeder Root 2"
"Junge - Blender Unit"
"Junge - Entry Screen"
"Junge - Printer"
"Economy Cntrls Bio Blend"
"Economy Cntrls Bio Blend #2"
"Economy Cntrls Bio Blend #3"
"CBT Computer 1"
"DAS Displays\ EEC"
"Subway Gift Card Terminal"
"Loyalty Kiosk"
"Mobile 2 Go Display"
"Transflo 1"
"Transflo 2"
"Mr. Payroll/ Western Union"
"CAT Scales 1"
"CAT Scales 2"
"CNG Monitoring Equipment"
"Cash Recycler"
"FlintLoc"
"Warren Rogers"
"HVAC - GridPoint"
"HVAC - Gilbarco Wisdom"
"Vintech System"
"TirePass Fuel Desk Comp"
"APC/UPS Non-Secure"
"TirePass Receipt Printer"
"OPTO22 Panel - Voltage"
"Laser Printer - Fuel Desk"
"TirePass PC Controller"
"TirePass Inflator Switch 1"
"TirePass Inflator Switch 2"
"TirePass Inflator Switch 3"
"TirePass Inflator Switch 4"
"TirePass Handheld 1 (Only if there is an Apon lane 17)"
"TirePass Handheld 2 (Only if there is an Apon lane 17)"
"Router"
"Load Balance NIC 1&2"
"iDRAC (Server)"
"KACE"
"KACE DHCP Reserve 1"
"KACE DHCP Reserve 2"
"KACE DHCP Reserve 3"
"KACE DHCP Reserve 4"
"Store Back Office"
"POS #1"
"POS #2"
"POS #3"
"POS #4"
"POS #5"
"POS #6"
"POS #7"
"POS #8"
"POS #9"
"Rest. Back Office"
"Rest. POS #1"
"Rest. POS #2"
"Rest. POS #3"
"Rest. POS #4"
"Rest. POS #5"
"Rest. POS #6"
"RBOS #2"
"FCC 1"
"Rest. Kitchen Video #1"
"Rest. Kitchen Video #2"
"Rest. Kitchen Video #3"
"Rest. Kitchen Video #4"
"Rest. Kitchen Video #5"
"NexGen 1"
"NexGen 2"
"FCC 2"
"Verifone - Diesel Desk"
"Verifone - Gas Desk"
"Verifone - Food"
"Verifone - Tire Shop"
"Verifone - Xpient Counter"
"MWS 1 (M1)"
"MWS 2 (M2 or AA Station)"
"Rest. MWS Standalone"
"RFID Reader 1"
"RFID Reader 2"
"RFID Reader 3"
"RFID Reader 4"
"RFID Reader 5"
"Car Wash Pedestals 2"
"Storage MWS 1 (U1)"
"Storage MWS 1 (U2)"
"Wireless Routers (Sagenet)"
"Wireless Routers (Sagenet)"
"Tire Shop Router"
"Tire Shop WAP #1 - Cisco"
"Tire Shop WAP #2 - Cisco"
"Tire Shop Computer 1"
"Tire Shop Computer 2"
"Tire Shop Maddenco/CBT"
"Tire Shop CBT"
"Laser Printer - Tire Shop 1"
"Laser Printer - Tire Shop 2"
"Tire Shop Noregon PC"
"Tire Shop Noregon DLA"
"Tire Shop Noregon PC (2nd Connection)"
) do (
for /L %%f in (0,1,217) do (
   echo pinging %%d with %three_octets%.%%f 1>&2
   ping -w 200 -l 1 %three_octets%.%%f |find "TTL=" >nul
   if not errorlevel 1 (echo %%d,%three_octets%.%%f is UP!) else (echo %%d,%three_octets%.%%f is DOWN!)
))>"%dat%"
echo The script is done, you can find the full log on your desktop
pause

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: bat to export results to 2nd column.

#15 Post by Squashman » 23 Jun 2016 14:15

So basically are you saying that the 4th octet of the IP address always corresponds to that device no matter what subnet it is in?

Post Reply