|
|
|
ping bat file
|
Original Message
|
Name: herbertk
Date: June 16, 2008 at 02:29:11 Pacific
Subject: ping bat fileOS: XPCPU/Ram: core 2 dual 2GBModel/Manufacturer: HP 2700 |
Comment: Hi all, im trying to write a bat file that will keep pinging a ip address lets say 10.174.10.48. if the ping fail then it will run another bat file eg restart.bat.. can anyone help me will the codes.. thx
Report Offensive Message For Removal
|
|
Response Number 1
|
Name: klint
Date: June 16, 2008 at 03:36:40 Pacific
Subject: ping bat file |
Reply: (edit)How about a one-liner: ping -n 1 10.174.10.48 | find "unreachable" >nul && call restart.bat The above will do the check once. It can be put in a loop if you want.
Report Offensive Follow Up For Removal
|
|
Response Number 3
|
Name: herbertk
Date: June 16, 2008 at 20:20:56 Pacific
Subject: ping bat file |
Reply: (edit)hi all, anyway to keep pinging the IP address and if ping fails run file.exe, wait for the exe to complete running then start pinging again?? thx alot
Report Offensive Follow Up For Removal
|
|
Response Number 4
|
Name: Mechanix2Go
Date: June 18, 2008 at 00:22:08 Pacific
Subject: ping bat file |
Reply: (edit)@echo off setLocal EnableDelayedExpansion :loop ping 10.174.10.48 | find /i "reply" > nul if errorlevel 1 file.exe ping 1.1.1.1 -n 1 -w 60000 > nul goto :loop ===================================== If at first you don't succeed, you're about average.M2
Report Offensive Follow Up For Removal
|
|
Response Number 5
|
Name: herbertk
Date: June 18, 2008 at 00:57:14 Pacific
Subject: ping bat file |
Reply: (edit)Hi M2, is it possible to change the codes to if ping is getting "Request timed out" for 10 continuous times then run the exe file.. thx again
Report Offensive Follow Up For Removal
|
|
Response Number 6
|
Name: Mechanix2Go
Date: June 18, 2008 at 11:54:47 Pacific
Subject: ping bat file |
Reply: (edit)@echo off setLocal EnableDelayedExpansion:loop for /f "tokens=* delims= " %%i in ('ping 10.174.10.48 ^| find /i "Request timed out"') do ( set /a bad+=1 echo bad count is !bad! ) if !bad! geq 10 file.exe ping 1.1.1.1 -n 1 -w 6000 > nul goto :loop
===================================== If at first you don't succeed, you're about average.M2
Report Offensive Follow Up For Removal
|
|
Response Number 7
|
Name: herbertk
Date: June 18, 2008 at 20:56:29 Pacific
Subject: ping bat file |
Reply: (edit)hi M2, is is possible to reset the bad count to 0 when there is a reply from the ping? the code that u written will count all "Request timed out" even if there is a reply from ping in between the "Request timed out". i need to count for : "Request timed out" "Request timed out" "Request timed out" "Request timed out" "Request timed out" "Request timed out" "Request timed out" "Request timed out" "Request timed out" "Request timed out" then run the file.exe thx
Report Offensive Follow Up For Removal
|
|
Response Number 8
|
Name: Mechanix2Go
Date: June 18, 2008 at 23:34:54 Pacific
Subject: ping bat file |
Reply: (edit)@echo off setLocal EnableDelayedExpansion :loop ping -n 2 10.174.10.48 >> log find /i "Reply" < log > nul if not errorlevel 1 type nul > log & goto :loop for /f "tokens=1" %%a in ('find /c /i "Request timed out" ^< log') do ( if %%a geq 10 echo file.exe && type nul > log ) goto :loop ===================================== If at first you don't succeed, you're about average.M2
Report Offensive Follow Up For Removal
|
|
Response Number 9
|
Name: lio_charmed
Date: July 24, 2008 at 02:55:58 Pacific
Subject: ping bat file |
Reply: (edit)hi can any one help me pleas i want to ping many ip and save them to text file then send them by mail in a batch file. thanks this is working but i want to add many ip: @echo off setLocal EnableDelayedExpansion :loop ping -n 2 192.168.100.1 >> log.txt find /i "Reply" < log.txt > if not errorlevel 1 type nul > log.txt & goto :loop for /f "tokens=1" %%a in ('find /c /i "Request timed out" ^< log.txt') do ( if %%a geq 10 echo file.exe && type nul > log.txt ) goto :loop
Report Offensive Follow Up For Removal
|
|
Response Number 10
|
Name: Mechanix2Go
Date: July 24, 2008 at 03:23:48 Pacific
Subject: ping bat file |
Reply: (edit)Do you want to check each one in a list ONCE then go through the list agin until ONE or ALL trigger at 10? BTW: is this meant to have a file name after > ? find /i "Reply" < log.txt > ===================================== If at first you don't succeed, you're about average.M2
Report Offensive Follow Up For Removal
|
|
Response Number 11
|
Name: lio_charmed
Date: July 24, 2008 at 04:50:45 Pacific
Subject: ping bat file |
Reply: (edit)i have a problem with network cables i don't know wen it is plugged or not.and i have 25 computers so i want a bat file to ping all ip that i well enter and wen he well finish the ping save the result to .txt file then send them by outlook to some email . so can you help me pleas
Report Offensive Follow Up For Removal
|
|
Response Number 12
|
Name: Mechanix2Go
Date: July 24, 2008 at 05:19:52 Pacific
Subject: ping bat file |
Reply: (edit)This wil create a log but I don't know how to script outlook. ::================================== for /f "tokens=* delims= " %%a in (IPlist) do ( ping %%a >> pinglog )
===================================== If at first you don't succeed, you're about average.M2
Report Offensive Follow Up For Removal
|
|
Response Number 13
|
Name: lio_charmed
Date: July 24, 2008 at 05:27:11 Pacific
Subject: ping bat file |
Reply: (edit)thank youuuuuuuu you have helped me very much.and pleas if you or some one find out how to send a text file by outlook or e-mail tell me pleassssss thanks again
Report Offensive Follow Up For Removal
|
|
Response Number 15
|
Name: lio_charmed
Date: July 24, 2008 at 08:20:04 Pacific
Subject: ping bat file |
Reply: (edit)hi Mechanix2Go, sorry to bother you again but just i am wandering how can i save only the "Request timed out" in the .txt file. thanks for helping
Report Offensive Follow Up For Removal
|
|
Response Number 16
|
Name: Mechanix2Go
Date: July 24, 2008 at 08:25:39 Pacific
Subject: ping bat file |
Reply: (edit)::================================== for /f "tokens=* delims= " %%a in (IPlist) do ( ping %%a | find "Request timed out" >> pinglog ) ===================================== If at first you don't succeed, you're about average.M2
Report Offensive Follow Up For Removal
|
|
Response Number 17
|
Name: lio_charmed
Date: July 24, 2008 at 08:58:10 Pacific
Subject: ping bat file |
Reply: (edit)HI Mechanix2Go, help me pleasss i have tried this but she didn't work @echo off setLocal EnableDelayedExpansion :loop ping -n 2 192.168.100.1 >> log.txt ping -n 2 192.168.100.2 >> log.txt ping -n 2 192.168.100.3 >> log.txt find /i "Reply" < log.txt > if not errorlevel 1 type nul > log.txt & goto :loop for /f "tokens=1" %%a in ('find /c /i "Request timed out" ^< log.txt') do ( if %%a geq 10 echo file.exe && type nul > log.txt ) for /f "tokens=* delims= " %%a in (IPlist) do ( ping %%a | find "Request timed out" >> pinglog.txt ) MAILTO.exe -v sender -d admin -at log.txt -n test@hotmail.com i know this is not right so pleas help me
Report Offensive Follow Up For Removal
|
|
Response Number 18
|
Name: Mechanix2Go
Date: July 24, 2008 at 09:03:38 Pacific
Subject: ping bat file |
Reply: (edit)Are you getting the expected logs? The loops? or what? ===================================== If at first you don't succeed, you're about average.M2
Report Offensive Follow Up For Removal
|
|
Response Number 19
|
Name: lio_charmed
Date: July 24, 2008 at 09:14:49 Pacific
Subject: ping bat file |
Reply: (edit) @echo off setLocal EnableDelayedExpansion :loop ping -n 2 192.168.100.1 >> log.txt ping -n 2 192.168.100.2 >> log.txt ping -n 2 192.168.100.3 >> log.txt find /i "Reply" < log.txt > if not errorlevel 1 type nul > log.txt & goto :loop
for /f "tokens=* delims= " %%a in (IPlist) do ( ping %%a | find "Request timed out" >> pinglog.txt ) she didn't work ?? i want to ping all my ip and only the Request timed out save them to the .txt file
Report Offensive Follow Up For Removal
|
|
Response Number 20
|
Name: Mechanix2Go
Date: July 24, 2008 at 09:24:59 Pacific
Subject: ping bat file |
Reply: (edit)Then you use the FIND after the ping. ===================================== If at first you don't succeed, you're about average.M2
Report Offensive Follow Up For Removal
|
|
Response Number 21
|
Name: lio_charmed
Date: July 26, 2008 at 02:40:34 Pacific
Subject: ping bat file |
Reply: (edit)Dear mechanix2go. if you pleas can you give me the complete bat file code to this: i want to ping all IP that i have entered in the txt and only the "Request timed out" save them to the .txt file Best regard
Report Offensive Follow Up For Removal
|
|
Response Number 22
|
Name: Mechanix2Go
Date: July 26, 2008 at 05:34:32 Pacific
Subject: ping bat file |
Reply: (edit)@goto :start Hi, This thread has had a few twists and has gotten confusing. if what you need is to ping a lisy and log only those which timed out, try the code below. If it's more complex, you may want to start a new thread. ::=========================================== :start @echo off setLocal EnableDelayedExpansion for /f "tokens=* delims= " %%a in (IPlist) do ( echo ================================ >> timedout.txt echo %%a >> timedout.txt ping %%a | find "Request timed out" >> timedout.txt ) ===================================== If at first you don't succeed, you're about average.M2
Report Offensive Follow Up For Removal
|
|
Response Number 23
|
Name: lio_charmed
Date: July 26, 2008 at 07:34:45 Pacific
Subject: ping bat file |
Reply: (edit)Hi mechamix2go, i have run this : :start @echo off setLocal EnableDelayedExpansion ping -n 2 192.168.100.101 >> timedout.txt ping -n 2 192.168.100.140 >> timedout.txt for /f "tokens=* delims= " %%a in (IPlist) do ( echo ================================ >> timedout.txt echo %%a >> timedout.txt ping %%a | find "Request timed out" >> timedout.txt ) the result is : *Pinging 192.168.100.101 with 32 bytes of data: Reply from 192.168.100.101: bytes=32 time<1ms TTL=128 Reply from 192.168.100.101: bytes=32 time<1ms TTL=128 Ping statistics for 192.168.100.101: Packets: Sent = 2, Received = 2, Lost = 0 (0% loss), Approximate round trip times in milli-seconds: Minimum = 0ms, Maximum = 0ms, Average = 0ms *Pinging 192.168.100.140 with 32 bytes of data: Request timed out. Request timed out. Ping statistics for 192.168.100.140: Packets: Sent = 2, Received = 0, Lost = 2 (100% loss), what is wrong???
Report Offensive Follow Up For Removal
|
|
Response Number 24
|
Name: Mechanix2Go
Date: July 26, 2008 at 07:56:55 Pacific
Subject: ping bat file |
Reply: (edit)These 2 lines put the result into timedout.txt regardless of what they are. Don't you want to put the IPs into a file called IPlist? If not and you just want to specify these 2: ::============================================ ping -n 2 192.168.100.101 | find "Request timed out" >> timedout.txt ping -n 2 192.168.100.140 | find "Request timed out" >> timedout.txt ::============================== Sorry this is not more clear. I may be going out shortly but I'll get back to you and work with you til it's solved. ===================================== If at first you don't succeed, you're about average.M2
Report Offensive Follow Up For Removal
|
|
Response Number 25
|
Name: lio_charmed
Date: July 27, 2008 at 01:12:57 Pacific
Subject: ping bat file |
Reply: (edit)hi mechamix2go, you are Genius :) thanks i have understand now its working , like i told you i have 25 POS computers and every day i synchronize sales now i can find out for sure if the sales is correct. now i have add it to the Scheduled Tasks in control panel at morning but i have see that the batch file modify and add the new ping in the timedout.txt . if i want to automatically rename the result 'timedout.txt' to the date that i have run the batch file. or 'export the result to the date that i have run the bat file.' can you pleas help me with this? :$
Report Offensive Follow Up For Removal
|
|
Response Number 26
|
Name: Mechanix2Go
Date: July 27, 2008 at 08:41:27 Pacific
Subject: ping bat file |
Reply: (edit)Do this and post result: echo %date% ===================================== If at first you don't succeed, you're about average.M2
Report Offensive Follow Up For Removal
|
|
Response Number 27
|
Name: lio_charmed
Date: July 28, 2008 at 03:07:03 Pacific
Subject: ping bat file |
Reply: (edit)hi mechmix2go, where i want to put "echo %date%"?? coz this only show me the date. when the batch file export the .txt file i want to name it with the curent date . example: if today is 22/07/2008 the name of the .txt file be 22.07.2008.txt or 22072008.txt . can bat file do it?? thanks best regard LEO.
Report Offensive Follow Up For Removal
|
|
Response Number 28
|
Name: klint
Date: July 28, 2008 at 03:25:16 Pacific
Subject: ping bat file |
Reply: (edit)Leo, I think M2 simply wants you to type echo %date% at the command prompt and post the resulting output. This may seem silly, but it is because everyone's %date% variable may produce differently formatted output, depending on which country they are in. For example, it could be 22/7/08, 22/07/2008, 7/22/2008, 2008-07-22 etc. (Just answering for M2 to speed things up in case it's currently night-time in M2's time zone. Apologies if I'm interfering.)
Report Offensive Follow Up For Removal
|
|
Response Number 29
|
Name: lio_charmed
Date: July 29, 2008 at 02:25:55 Pacific
Subject: ping bat file |
Reply: (edit)thank you all now its working very good this is the source code : :start @echo off setLocal EnableDelayedExpansion echo %date% for /f "tokens=* delims= " %%a in (IPlist) do ( echo ================================ >> %date% echo %%a >> %date% ping %%a | find "Request timed out" >> %date% ) Best Regard, LEO
Report Offensive Follow Up For Removal
|
|
Response Number 31
|
Name: lio_charmed
Date: August 29, 2008 at 08:55:48 Pacific
Subject: ping bat file |
Reply: (edit)hi sagven55, this is the the final source code. but if you want 25 computer you must enter there IPs in text file named 'iplist' like: 192.168.100.1 192.168.100.2 192.168.100.3 then save it @echo off setLocal EnableDelayedExpansion echo %date% for /f "tokens=* delims= " %%a in (IPlist) do ( echo ================================ >> %date% echo %%a >> %date% ping %%a | find "Request timed out" >> %date% ) this is all ;-)
Report Offensive Follow Up For Removal
|
Use following form to reply to current message:
|
|

|