Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

batch script help

Status
Not open for further replies.
Oct 9, 2003
174
US
I am looking to write a script that will do the following.

The script, running on server-A will do a continuous ping over to server-B. If the ping between the two servers is successful then take no action but if the ping fails, I need to log the time that it fails and also log the time that it becomes successful again.

It seems pretty simple in theroy but batch scripting is not my strong suit. Can anyone help with this?

Thanks
 
I can start you off with something but don't have time for all;

:begin
ping -n 1 borg.hostname >>log.txt | find /i "reply"
if errorlevel 1 goto noreply
if errorlevel 0 goto reply

:reply
goto repeat

:noreply
REM ENTER ACTION HERE
goto repeat

:repeat
goto begin

:end

You'll need to use "time/t" and "date/t" to get stamps.
 
******************************************
:begin
ping -n 1 xxx.xxx.xxx.xxx | find /i "reply"
if errorlevel 1 goto noreply
if errorlevel 0 goto reply


:reply
goto repeat

:noreply
ECHO %DATE% >> log.txt
ECHO %TIME% >> log.txt
goto repeat

:repeat
goto begin

:end
*************************************

Thank you wallst, this worked good. It logs the failed ping attempts to the log.txt file but after testing it out a little, the output gets very ugly in the log file.

Is there any way that you know of to have the script log "down time". What I mean is send a time stamp when the ping response begins to fail and then another when the connection gets re-established.

That would be really what I was looking for this thing to do.

I really appreciate everyones help,
Thanks

 
I think i got it, thanks for the start again Wallst.

*************************************
:begin
ping -n 1 xxx.xxx.xxx.xxx | find /i "reply"
if errorlevel 1 goto noreply
if errorlevel 0 goto reply

:reply
goto repeat

:noreply
ECHO DOWN @ %DATE% --- %TIME% >> log.txt
goto noreplyloop

:repeat
goto begin

:noreplyloop
ping -n 1 xxx.xxx.xxx.xxx | find /i "reply"
if errorlevel 1 goto noreplyloop
if errorlevel 0 goto replyloop

:replyloop
ECHO UP @ %DATE% --- %TIME% >> log.txt
ECHO " " >> log.txt
ECHO " " >> log.txt
goto repeat

:end
***********************************
OUTPUT WILL LOOK LIKE THIS:

DOWN @ Wed 03/16/2005 --- 7:53:16.13
UP @ Wed 03/16/2005 --- 7:54:05.70


Maybe not the most efficent way of doing it but it will work for what I need.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top