Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm trying to make (hopefully a simple) script that when run pings my mobile device. If the mobile is connected to the network it will execute one command and if not it will execute another.

I've tried with the following command:

ping -n 1 (The IP) >nul    
IF ERRORLEVEL 0 GOTO safe    
IF ERRORLEVEL 1 GOTO alarm

:safe    
start home.mp3    
GOTO end

:alarm    
start alarm.mp3    
GOTO end

:end
exit

This actually worked once, but since then it doesn't work after the first ping. Is it something I'm missing? Perhaps there's an easier way of doing this?

share|improve this question
    
FYI - the reason this doesn't work is because the ping command does not set the errorlevel based on the result of the ping. We used to have a command line tool called "alive" that did that. –  uSlackr Jun 8 '12 at 2:30

2 Answers 2

ping -n 1 xxx.yyy.zzz.www | findstr TTL && start home.mp3
ping -n 1 xxx.yyy.zzz.www | findstr TTL || start alarm.mp3
share|improve this answer
    
This worked perfectly. Finally I can go to sleep. Thank you so much!!! –  Anton Johnsson Jun 7 '12 at 23:47
    
@AntonJohnsson So this answered your question? Why did you not accept the answer? –  utrecht Oct 18 at 15:43
ping -n 1 COMPUTERNAME | findstr TTL && start home.mp3 || start alarm.mp3
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.