batch file to continuous PING multiple IP and domain with date/timestamp on a notepad file
Moderator: DosItHelp
-
- Posts: 8
- Joined: 05 Jun 2016 21:17
batch file to continuous PING multiple IP and domain with date/timestamp on a notepad file
Hi, I'm new to this forum and not that good with batch files and scripting. I've made some research about continuously pinging an IP or domain with date/timestamp. The purpose of this is to compare with our ISP whenever they have downtime or intermittent connection. Below is the command I've used
ping -t <ip address>|cmd /q /v /c "(pause&pause)>nul & for /l %a in () do (set /p "data=" && echo(!date! !time! !data!)&ping -n 2 ip address>nul" >C:\filename.txt
This command works when I manually copied/paste this command on a command prompt, with or without admin rights
But when I tried this on a batch file just like the command below:
@echo off
ping -t <ip address>|cmd /q /v /c "(pause&pause)>nul & for /l %a in () do (set /p "data=" && echo(!date! !time! !data!)&ping -n 2 ip address>nul" >C:\filename.txt
it just shows filename.txt was unexpected at this time.
No errors shown on event viewer. Am I missing something here?
Thanks
Jeff
ping -t <ip address>|cmd /q /v /c "(pause&pause)>nul & for /l %a in () do (set /p "data=" && echo(!date! !time! !data!)&ping -n 2 ip address>nul" >C:\filename.txt
This command works when I manually copied/paste this command on a command prompt, with or without admin rights
But when I tried this on a batch file just like the command below:
@echo off
ping -t <ip address>|cmd /q /v /c "(pause&pause)>nul & for /l %a in () do (set /p "data=" && echo(!date! !time! !data!)&ping -n 2 ip address>nul" >C:\filename.txt
it just shows filename.txt was unexpected at this time.
No errors shown on event viewer. Am I missing something here?
Thanks
Jeff
Re: batch file to continuous PING multiple IP and domain with date/timestamp on a notepad file
From the FOR command help file.
To use the FOR command in a batch program, specify %%variable instead
of %variable. Variable names are case sensitive, so %i is different
from %I.
-
- Posts: 8
- Joined: 05 Jun 2016 21:17
Re: batch file to continuous PING multiple IP and domain with date/timestamp on a notepad file
I tried to use double %%a on the command, it showed like this.
@echo off
ping -t <ip address>|cmd /q /v /c "(pause&pause)>nul & for /l %%a in () do (set /p "data=" && echo(!date! !time! !data!)&ping -n 2 <ip address>>nul" > C:\<filename>.txt
so when I run this command, a command window opened up for a quick sec and disappeared.
Regards,
Jeff
@echo off
ping -t <ip address>|cmd /q /v /c "(pause&pause)>nul & for /l %%a in () do (set /p "data=" && echo(!date! !time! !data!)&ping -n 2 <ip address>>nul" > C:\<filename>.txt
so when I run this command, a command window opened up for a quick sec and disappeared.
Regards,
Jeff
Re: batch file to continuous PING multiple IP and domain with date/timestamp on a notepad file
It would help to see the kind of output you are after from the ping command. Copy and paste a sample here.
I'd also curious to know if this has to be a one liner.
I'd also curious to know if this has to be a one liner.
-
- Posts: 8
- Joined: 05 Jun 2016 21:17
Re: batch file to continuous PING multiple IP and domain with date/timestamp on a notepad file
Here's a sample output of the command.
Wed 06/08/2016 9:19:33.22 Reply from <ip address being PING>: bytes=32 time=1ms TTL=254
As you can see on this output, this shows not only the latency but also the exact date and time. And this output is shown in a notepad/ txt document created in drive C
The purpose of this is to have a record since PING results has a limit, it will truncate the earlier results and it is hard for us to prove with our ISP if there's intermittent connection.
Thanks
Jeff
Wed 06/08/2016 9:19:33.22 Reply from <ip address being PING>: bytes=32 time=1ms TTL=254
As you can see on this output, this shows not only the latency but also the exact date and time. And this output is shown in a notepad/ txt document created in drive C
The purpose of this is to have a record since PING results has a limit, it will truncate the earlier results and it is hard for us to prove with our ISP if there's intermittent connection.
Thanks
Jeff
Re: batch file to continuous PING multiple IP and domain with date/timestamp on a notepad file
Thanks.
These questions are to help me understand the requirement just a little more. I ask these due to past experience with similar questions and to avoid misunderstandings that have happened in the past.
Is the purpose of this to have a log for review after the ping command has terminated?
Does it all need to be in a single line of code?
These questions are to help me understand the requirement just a little more. I ask these due to past experience with similar questions and to avoid misunderstandings that have happened in the past.
Is the purpose of this to have a log for review after the ping command has terminated?
Does it all need to be in a single line of code?
-
- Posts: 8
- Joined: 05 Jun 2016 21:17
Re: batch file to continuous PING multiple IP and domain with date/timestamp on a notepad file
Yes, the purpose of this is to have a record in a notepad file or text file to check previous timestamp not just the previous.
What do you mean by "Does it all need to be in a single line of code?"
Thanks
Jeff
What do you mean by "Does it all need to be in a single line of code?"
Thanks
Jeff
Re: batch file to continuous PING multiple IP and domain with date/timestamp on a notepad file
What's wrong with the logs in your router, (most routers even have a facility to select the information in those logs), and write them to file.
Additionally, why run a constant ping, can you not just run one every minute for instance.
Single command: run it as a scheduled task every minute
Additionally, why run a constant ping, can you not just run one every minute for instance.
Code: Select all
@Echo Off
:Loop
For /F "Skip=4 Tokens=*" %%a In (
'Echo(Prompt $D$T$S^|(Cmd^&Ping -n 1 216.58.198.174^|Find "TTL"^)'
) Do Echo(%%a>>C:\Output.log
Timeout 60 1>Nul
GoTo :Loop
Single command: run it as a scheduled task every minute
Code: Select all
Echo(Prompt $D$T$S|(Cmd^&Ping -n 1 216.58.198.174|Find "TTL")|Find "TTL">>C:\Output.log
Re: batch file to continuous PING multiple IP and domain with date/timestamp on a notepad file
jepoytengco wrote: it will truncate the earlier results
Not understanding what you mean by this.
Re: batch file to continuous PING multiple IP and domain with date/timestamp on a notepad file
jepoytengco wrote:when I run this command, a command window opened up for a quick sec and disappeared.
To debug your code, open Cmd window first, then run the batch in it, post output here.
-
- Posts: 8
- Joined: 05 Jun 2016 21:17
Re: batch file to continuous PING multiple IP and domain with date/timestamp on a notepad file
Squashman wrote:jepoytengco wrote: it will truncate the earlier results
Not understanding what you mean by this.
What I mean here, it will just push the earlier messages upwards and you wont be able to see them anymore.
-
- Posts: 8
- Joined: 05 Jun 2016 21:17
Re: batch file to continuous PING multiple IP and domain with date/timestamp on a notepad file
sambul35 wrote:jepoytengco wrote:when I run this command, a command window opened up for a quick sec and disappeared.
To debug your code, open Cmd window first, then run the batch in it, post output here.
Wow!, guess what? Sambul has a point in this. I tried to opened up a command prompt first then run the <file>.bat then it worked. What am I missing here?
Thanks
Jeff
Re: batch file to continuous PING multiple IP and domain with date/timestamp on a notepad file
The following single line in a batch file appears to be working for me!The cmd windows stays open.
This however doesn't!The cmd window closes immediately.
The difference… I cannot write to the root of C:\
Code: Select all
@Ping -t 216.58.198.174|Cmd /Q /V /C "(Pause&Pause)>Nul&For /L %%a In () Do (Set/P "Data="&&Echo(!Date! !Time! !Data!)&Ping -n 2 216.58.198.174>Nul">C:\Users\Compo\Desktop\Output.log
This however doesn't!
Code: Select all
@Ping -t 216.58.198.174|Cmd /Q /V /C "(Pause&Pause)>Nul&For /L %%a In () Do (Set/P "Data="&&Echo(!Date! !Time! !Data!)&Ping -n 2 216.58.198.174>Nul">C:\Output.log
The difference… I cannot write to the root of C:\
-
- Posts: 8
- Joined: 05 Jun 2016 21:17
Re: batch file to continuous PING multiple IP and domain with date/timestamp on a notepad file
I think I know what the problem is. I tried to change the path instead of drive C, I switched it to the desktop and it worked. I think there's a security issue here but I'm not sure whether it is a security issue or not.
Thanks
Jeff
Thanks
Jeff
-
- Posts: 8
- Joined: 05 Jun 2016 21:17
Re: batch file to continuous PING multiple IP and domain with date/timestamp on a notepad file
Its ok if it doesn't work on drive C, its ok if it shows output in my desktop, my next objective is if I type in the command this way:
It just shows the first command line, it doesn't runs the second file2. I'm guessing I need an "and" connector? so that it will run both commands.
Thanks
Jeff
Code: Select all
@echo off
ping -t <ip address>|cmd /q /v /c "(pause&pause)>nul & for /l %%a in () do (set /p "data=" && echo(!date! !time! !data!)&ping -n 2
<ip address>>nul" > C:\users\jefferson.co\desktop\ping\<file1>.txt
ping -t <ip address>|cmd /q /v /c "(pause&pause)>nul & for /l %%a in () do (set /p "data=" && echo(!date! !time! !data!)&ping -n 2
<ip address>>nul" > C:\users\jefferson.co\desktop\ping\<file2>.txt
It just shows the first command line, it doesn't runs the second file2. I'm guessing I need an "and" connector? so that it will run both commands.
Thanks
Jeff