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

Posted on 2006-06-07
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
    LVL 4

    Accepted Solution

    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.
    LVL 4

    Author Comment

    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.
    LVL 4

    Expert Comment

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

    Author Comment

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

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    find a node in VST 2 37
    countPairs challenge 7 39
    mapAB Challlenge 35 52
    wordlen challenge 3 29
    A short article about problems I had with the new location API and permissions in Marshmallow
    This is about my first experience with programming Arduino.
    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 fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

    728 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

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now