Log ping and date isn't working

3

1

:START
echo %date% %time% && ping -n 1 192.168.1.1 >> pingReport.txt 2>&1
echo %date% %time% && ping -n 1 192.168.1.2 >> pingReport.txt 2>&1
echo %date% %time% && ping -n 1 192.168.1.3 >> pingReport.txt 2>&1
echo %date% %time% && ping -n 1 192.168.1.4 >> pingReport.txt 2>&1
goto START

This echos Date and time on my screen only, but not into the file.

How can I get date and time in the txt file too?

Henricristo

Posted 2013-10-02T11:54:42.373

Reputation: 33

Question was closed 2013-10-08T17:53:34.980

What OS and/or shell is this? The 2>&1 looks *nix-esque, but the use of %date% and %time% hints at a Microsoft OS. The answer will likely be different depending on what OS and shell you want it for. – a CVn – 2013-10-02T12:19:30.597

Answers

3

echo and ping are two commands separated by "&&". The way you wrote it, the second command (after "&&") is sent to the text file.

If you want both commands output to be sent to the text file, you can put them inside parentheses:

:START
(echo %date% %time% && ping -n 1 192.168.1.1) >> pingReport.txt 2>&1
(echo %date% %time% && ping -n 1 192.168.1.2) >> pingReport.txt 2>&1
(echo %date% %time% && ping -n 1 192.168.1.3) >> pingReport.txt 2>&1
(echo %date% %time% && ping -n 1 192.168.1.4) >> pingReport.txt 2>&1
goto START

Savvas Radevic

Posted 2013-10-02T11:54:42.373

Reputation: 1 056