How to create startup script that can execute certain commands based on if the server had an unexpected reboot

Posted on 2006-06-07
Medium Priority
Last Modified: 2010-04-17
I have two Windows 2003 servers and 3rd Linux based device.

If Server 1 crashed and rebooted it would need to reboot the Linux device, wait about a minutes, and then start a bunch of services on Server1.

If Server 2 crashed or rebooted unexpectedly it would need to stop services on Server 1 wait 30 seconds and then restart the services.  If it were rebooted gracefully, then none of this would need to happen.

I can do the commands using regular bat files, but I don't know how to determine if a reboot was unexpected or not.

If needed I expect I can have make it work.
Startup script does all the commands mentioned above
Shutdown script renames the startup script to something else and replaces it with a "safe" startup script.
The Safe startup script would rename the startup script back to what it should be.

I'd like to have something more elegant and not as complex.

Be warned, my scripting experience is limited to bat files issuing standard windows commands like netsvc or the like.  Be prepared for some very basic questions.

Question by:averyb
  • 2
  • 2

Accepted Solution

tomerlei earned 2000 total points
ID: 16855001
I have a solution that is similiar to your but a little more elegant.

In the startup scripts create a file on drive C:, u can even use that:

echo %DATE%>c:\unexpected.txt

and in the shutdown script:
del c:\unexpected.txt /q /f

and instead of having 2 startup scripts just use this IF sentence:

IF EXIST c:\unexpected.txt goto unexpected
goto end
[insert your operation here, or call another batch file using the CALL command]


I dont know of any other way to determine a clean shutdown.

Author Comment

ID: 16858213
That sounds like it'll work.

Any reason why I couldn't use the IF EXist to also check another server for a graceful shutdown?
I'd map a drive first.
net use z:\\server2\c$
If Exist z:\unexpected.txt goto unexpected
etc . . .

Thanks again.

Expert Comment

ID: 16860077
Ofcourse it will work, this will work either:
IF EXIST \\server2\c$\unexpected.txt goto unexpected
a bit more clean :)

Author Comment

ID: 16865165
I have another related question, but I'll open a new ticket for it.

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What do responsible coders do? They don't take detrimental shortcuts. They do take reasonable security precautions, create important automation, implement sufficient logging, fix things they break, and care about users.
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question