run a file, when remote computer become unvailable

Shahab

New Member
Hello masters. I'm newbie and have an urgent question
We have a SQL server in our remote office that stores accounting software databases.
I'd like to run a bat file (or an application), when the server is unavailable for a while.
for example, In case of the server ping timed out for 3 minutes, the warning message displayed on the clients desktop. Or when the server returns to the network, sync operation runs automatically.
In my researches, I found that some network monitoring tools do this job, based on ping of server. ie they can monitor a set of IPs and launch/close an application when the ping status changes. But I couldn't find any suitable solution.
Would you please help me to find a solution? any comment will appreciated
 
A scheduled task that stores the no connection results in a file/registry entry is probably easy enough to do. Running a batch file to track pings and then running whatever you wanted to do if it failed a certain number of times.

I found this snippet on stack overflow which is close to what you'd want. Basically what happens is it looks through and generates an IP and writes it to a file IF the host replied to ping.
Code:
@ECHO OFF
SET output=%USERPROFILE%\output.txt
IF EXIST "%output%" DEL "%output%"
FOR /L %%G IN (1, 1, 69) DO (
    CALL :ping 192.168.%%G.3
    CALL :ping 192.168.%%G.4
)
GOTO :EOF

:ping
ping -n 1 %1 | find "Approximate round trip" >NUL && ECHO %1>>"%output%"
 
A scheduled task that stores the no connection results in a file/registry entry is probably easy enough to do. Running a batch file to track pings and then running whatever you wanted to do if it failed a certain number of times.

I found this snippet on stack overflow which is close to what you'd want. Basically what happens is it looks through and generates an IP and writes it to a file IF the host replied to ping.
Code:
@ECHO OFF
SET output=%USERPROFILE%\output.txt
IF EXIST "%output%" DEL "%output%"
FOR /L %%G IN (1, 1, 69) DO (
    CALL :ping 192.168.%%G.3
    CALL :ping 192.168.%%G.4
)
GOTO :EOF

:ping
ping -n 1 %1 | find "Approximate round trip" >NUL && ECHO %1>>"%output%"


Thanks a lot dear admin for reply.
would you please explain more clearly.what i should to do now? I should to write the code in a bat file and then?
 
It's a batch file yes. And it's not really complete. It's got the building blocks you might be able to use. In itself, the code I gave you is somewhat useless.

Basically you'd need to modify it slightly. The main thing to note is actually the ping line
Code:
ping -n 1 %1 | find "Approximate round trip" >NUL && ECHO %1>>"%output%"
So what this line does is pings an IP address (you can hard code your address if you like) and pipes the output to the find command. && checks the status of the preceding command and if it was successful (in this case, if the machine at the IP address answered) writes the IP to a file.
 
Back
Top