|
Answer» Hello... I am working on a batch file that will constantly run in a timed loop using the choice command from an earlier Windows release in Windows XP Pro, with a 60 second timer, so that I dont have a constant ping to the systems being monitored. Everything works except I cant FIGURE out how to pass or (read) the OUTPUT to a condition to be tested for PINGING or NO PING in the batch.
I have everything working except for how to read the ping output so that IF its pinging, goto the beginning of the batch BACK to the Choice 60 second delay and wait another 60 seconds before testing again, and if the ping fails to goto the NEXT step in the batch which is to start the service on the next system which is a clone with a software mirror to pick up where the other server left off. I am doing this by Starting and Stopping Services via commands over the network from within the batch.
I have been able to Stop and Start the Services with my test batch and get the delay to work and loop as needed, but this PING condition test is new territory and I dont know how to get it to work. I searched the internet for others who have passed PING outputs to a variable or token to be tested and haven't found anything on it. I know I cant be the only one who has performed a batch task like this though. I dont see why the output cant be passed outside of the PING command to the batch to test the condition as Pinging or No Ping .... Any suggestions or a batch code snippet that might get me past this roadblock in my project.. :-? :-?
If I cant get the PING condition test to work, I was thinking of an alternative of placing a token file on each system to be monitored and if the token file can not be read, assume that the system is not on the network, and GO through with starting up the service on the redundant server, so that the server may only go down for 5 or 10 minutes maybe at max while services are started and the server joins back in. This would work, but its hoakey ... I'd like to read the PING state if possible to avoid this hoakey method. :-/
Thanks for your help on this .... DaveTry piping the output from the ping to a find. If you find "Request timed out" you have a non-response, if you find "Reply from" you know you got a response. You can check %errorlevel% to decide how to branch.
Just a suggestion. 8-)Hello Sidewinder, Thanks for the info...
I should probably take another shot at this in the morning, since I am coding after being up for almost 20 hours now. I ran into some problems with this code... Either I have my IF-Then-Else statement backwards or its not correctly reading the piped data from Ping to the Find. Too tired to troubleshoot further at this point. Maybe you can point out where I am going wrong with this. Its probably a stupid mistake that I am missing here...
The code below delays for 1 second calling to a Wait.bat batch file that is using the choice command with a variable for the time delay, passed from the Call Wait xx ( xx = seconds )
The code waits 1 second, then passes over to the next ping, then waits 1 second and goes to the last ping, and fails because there is no server on the IP of 192.168.1.107 yet, so t bails at the failed service start back to C:\>
Any suggestions on where I am going wrong with this...Its probably a few dumb mistakes... Thanks [smiley=thumbsup.gif]
@echo off :loop cls @echo. Server A Running CALL WAIT 1 ping 192.168.1.105 -n 1 | Find "Reply from" if not .%1==."Reply from" goto else goto endif :else sc "\\192.168.1.106" start spooler goto serverB :endif goto loop
:serverB :loop2 cls @echo. Server B Activated and Running CALL WAIT 1 ping 192.168.1.106 -n 1 | Find "Reply from" if not .%1==."Reply from" goto else goto endif :else sc "\\192.168.1.107" start spooler goto serverC :endif goto loop2
:serverB :loop2 cls @echo. Server C Activated and Running CALL WAIT 1 ping 192.168.1.107 -n 1 | Find "Reply from" if not .%1==."Reply from" goto else goto endif :else @echo. < BIG PROBLEM ... ALL SERVERS DOWN > PAUSE goto loop2 :endif goto loop2 @echo on You wrote:
Code: [Select]ping 192.168.1.105 -n 1 | Find "Reply from" if not .%1==."Reply from" goto else
My suggestion would be:
Code: [Select]ping 192.168.1.105 -n 1 | Find "Reply from" if errorlevel 1 goto else
I may have it *censored*-backwards, but I'm pretty sure it's correct. If it is backwards throw in a not on the if statement.
8-)
Using reserved words for your label names makes the code difficult to read. But maybe that's just me. 8-)does anyone could explain me why you use .%1 and not just %1 ?jerome,
If %1 are blanks or null, the command processor will flag it as an invalid statement. By using the dots, you ensure that there is something on both sides of the equal. The dots by the way are arbitrary, many people use quotes, dollar signs, or any other special symbol they take a liking to.
|