Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I am currently working in a big company and we have serious latency issues. This is happening in a process control system, and is unacceptable (Open a valve sometimes take 2 minuts before command start)

The Network team seems very lazy and I want to check when they say "everything alright on the network".

So, I want to create a loop that ping the server and write the result in a text file.

I am not a batch expert, but do you think this code is correct to use?

@ECHO OFF

:LOOPSTART

time /T
ping xxx.xx.x.x  -t >> filename.txt
sleep -m 3000

GOTO LOOPSTART
share|improve this question
    
oss.oetiker.ch/smokeping –  Zoredache Oct 11 '11 at 7:43
    
@Zoredache I cannot install such softwares on a Process control computer: dev.pulsed.net/wp/?p=31 –  Waza_Be Oct 11 '11 at 8:06
    
"win XP Professional" is not DOS. –  grawity Oct 11 '11 at 12:32

2 Answers 2

up vote 11 down vote accepted

Looks fine to me, but there's no need to loop it if you want to continuously ping the IP. Then you could simply do it like this:

@ECHO OFF
set IPADDRESS=x.x.x.x
ping %IPADDRESS% -t >> filename.txt

If you want to ping every X minute, use the loop:

@ECHO OFF
set IPADDRESS=x.x.x.x
set INTERVAL=60
:PINGINTERVAL
ping %IPADDRESS% -n 1 >> filename.txt
timeout %INTERVAL%
GOTO PINGINTERVAL

As you can see I replaced the sleep command with timeout. That's because sleep isn't always available on some systems whereas timeout usually is.

Missing sleep or timeout commands on your system? Don't fret. Just replace timeout with the following hack:

@ping 127.0.0.1 -n %INTERVAL% > nul

This hack simply pings your local address, and since it will respond instantly we can use this to emulate a delay in execution.

share|improve this answer
    
timeout is not recognized as an internal or external command –  Waza_Be Oct 11 '11 at 8:02
    
@Profete162, do you have the sleep command then? If so, just replace timeout with sleep. What version of Windows are you doing this? –  Marcus Ekwall Oct 11 '11 at 8:14
    
Same for sleep... I am using win XP Professional –  Waza_Be Oct 11 '11 at 8:21
    
@Profete162, old school! :) I'll add a secondary method which you can use when those commands are missing. –  Marcus Ekwall Oct 11 '11 at 8:22

I know it's a windows question (and an old one at that), but maybe it's similar to Linux and OSX. This is the first thing that came up when I was looking for a simple command to keep network traffic on my laptop. Might be useful to someone looking for something similar.

in a bash script:

WAITSECONDS=30 #or whatever your needs are
IPTOPING=8.8.8.8 #or whatever your needs are
ping -i ${WAITSECONDS} ${IPTOPING} > logfile

Single line ex pinging google dns every 30sec:

ping -i 30 8.8.8.8 > logfile

Works in OSX and Linux, should be pretty standard though, don't know what system you're on.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.