Jump to content

Do we have any good batch scripters?


FallenHoot
 Share

Recommended Posts

I have been searching around Google and stackoverflow for a script that will call the HTTP website and see if it is running. If it is running keep testing every 10 minutes. If it is not running, restart the service.
 
I want to run this on the server with Apatche Tomcat.
 
@
echo off




:first
    PING -n 5 google.com | FIND "TTL" > nul
    IF %errorlevel% == 0 (
        echo Website is up. 
goto :first
    ) ELSE (
        echo Website is down. Restarting service
goto :second
echo restart
echo ping
    )




:: This calls the second loop
:second


:: This will stop the service
net stop TapiSrv 


ping -n 10 127.0.0.1 


:: This will start the service
net start TapiSrv


:: This check to see if the website is up
GOTO :first
 

 

 
I need to figure out how to do the 10 minutes between each loop. If it fails and restarts the service. I need it to start the loop again.
Link to comment
Share on other sites

Wait so what did you get right? 

 

Still need to get the file to restart because ping isn't working?

 

edit: curious why you are pinging google 5 times as well... Shouldn't that be where the host ip is? Kind of a novice so forgive me if I'm wrong

Link to comment
Share on other sites

Wait so what did you get right? 

 

Still need to get the file to restart because ping isn't working?

 

edit: curious why you are pinging google 5 times as well... Shouldn't that be where the host ip is? Kind of a novice so forgive me if I'm wrong

 

 

So I can ping the server that the Apache Tomcat is running and I can restart the service if the ip is bad. 

 

I am just using Google as an example. It would only ping 5 times because the first ping may be bad.

 

 

Ping is working, but the service isn't. I can ping the server, which tells me it is working. Ping doesn't tell me that the website is up.. That is my issue now.. I should update the batch file since it has changed. I have been working on this for about 5 hours.. 

Link to comment
Share on other sites

I don't know I guess I'm a little confused. If you have your website's content on a server when its up and running that means your website is up and running and when that server goes down your website goes down. You ping the server and it's successful so doesn't that mean your website is up? Am I missing something? Did you make sure your Domain was correct and working? Some people forget to renew the Domain name and blame the host servers, but really it was the Domain issue.

Link to comment
Share on other sites

  • 3 weeks later...

Are you running this on a Linux box?

Since when is net stop a Linux command :p 

 

To answer the question putting something like the below to look for the tomcat services would probably be best, imho though you need to figure out why the service keeps dying as this is not normal behavior.

 

for /F "tokens=3 delims=: " %%H in ('sc query "MyServiceName" ^| findstr "        STATE"') do (
  if /I "%%H" NEQ "RUNNING" (
   REM Put your code you want to execute here
   REM For example, the following line
   net start "MyServiceName"
  )
)

 

btw this would be a VBS script not a batch script
 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...