1

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?

Wesley
  • 32,690
  • 9
  • 82
  • 117
Anton Johnsson
  • 11
  • 1
  • 1
  • 2
  • 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 08 '12 at 02:30

2 Answers2

4
ping -n 1 xxx.yyy.zzz.www | findstr TTL && start home.mp3
ping -n 1 xxx.yyy.zzz.www | findstr TTL || start alarm.mp3
Dusan Bajic
  • 2,056
  • 1
  • 18
  • 21
-1
ping -n 1 COMPUTERNAME | findstr TTL && start home.mp3 || start alarm.mp3
serdar
  • 127
  • 7