Ping with timestamp and log

Guys im using this script in a batch file to perform continuous ping with timestamp and to be recorded in a log file, it is working fine on my computer ( windows 8 64 bit ) but when i try to use it on a windows 7 machine also 64 bit, whenever i run the batch i keep getting that:

Could not find C:\user\administrator\pinglog.txt

knowing that i have created the file pinglog.txt but i really cant figure out the problem.

@echo off
del pinglog.txt
for /f "tokens=*" %%A in ('ping localhost -n 1 ') do (echo %%A>>pinglog.txt && GOTO Ping)
:Ping
for /f "tokens=* skip=2" %%A in ('ping localhost -n 1 ') do (echo %date% %time% %%A>>pinglog.txt && GOTO Ping) 

i appreciate any help. Thank you in advance

Upvotes: 0

Views: 17217

Answers (2)

Jean Fredson
Jean Fredson

Reputation: 111

Over PowerShell you can use this CLI.

ping.exe -t 10.227.23.241 |Foreach{"{0} - {1}" -f (Get-Date),$_} >> Ping_IP.txt

Upvotes: 5

MichaelS
MichaelS

Reputation: 6042

Could not find C:\user\administrator\pinglog.txt means that the file was not found. And the reason for this is really simple. The folder is called users and not user. So the correct path is C:\users\administrator\pinglog.txt.

Upvotes: 0

Related Questions