Results 1 to 1 of 1
  1. #1
    Join Date
    Jan 2004
    Posts
    545
    Provided Answers: 4

    Unanswered: Extended shutdown-script for ASE 12.5 & Win2k

    As I promised in this topic!
    After each segment of code, there is a short explanation.
    Questions can be mailed to martijn.vs_NO_SPAM_REMOVE_THIS_[at]gmail.com.
    I hope you enjoy it!
    All script used here are attached to this post. Remember to remove the .txt-extention before you try to use them
    Code:
    rem @echo off
    goto INIT
    REM ****************************************************
    REM  Program    : sybmaint.bat
    REM  By         : MFD van Soldt (PRU) 09/2004
    REM  Version    : 0.5
    REM  Purpose    : shutdown and disable restart databaseservice
    REM  Parameters : shutdowntype or startup
    REM ****************************************************
    Header of the script. Feel free to distribute the script and share it with friends, as long as you keep this original header intact.
    Code:
    REM -------------------------------------------------------
    REM          INIT
    REM -------------------------------------------------------
    :INIT
    call %SYB_MAINT_DIR%\ini\setenv.bat
    Call the setenv.bat-script. It sets all neccesary environmentvariables. See this[link] post for more info about the setenv.bat-stuff. Attached to this post is a similar setenv.bat-file.
    The %SYB_MAINT_DIR% variable contains the path of the directory where the scripts and the model.reg-file are located.
    Code:
    REM
    REM  Checks
    REM 
    if "%SYB_SERVER%"=="" goto NOSERVER
    if "%SYB_MAINT_USER%"=="" goto NOUSER
    if "%SYB_MAINT_PW%"=="" goto NOPASSWORD
    Checks if variables are empty. They cannot be empty, as they are used to connect to the server through an isql-session.
    Code:
    REM -------------------------------------------------------
    REM          PARAMETERS
    REM -------------------------------------------------------
    SET ACTION=%1
    
    if "%ACTION%" == "" 		goto USAGE
    if %ACTION% == "sd_manual" 	goto REGKEY
    if %ACTION% == "sd_once" 	goto GEN_SCRIPT
    if %ACTION% == "su_enable" 	goto STARTUP_AUTO
    goto USAGE
    Checks if the ACTION-parameter is emtpy. This parameter tells the script to shutdown once, shut down permanently or to startup.
    Code:
    REM
    REM -------------------------------------------------------
    REM          CREATE REGKEY
    REM -------------------------------------------------------
    :REGKEY
    copy %SYB_MAINT_DIR%\model.reg  %SYB_MAINT_DIR%\sybasestartup.reg
    
    echo [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\SYBSQL_%SYB_SERVER%]>> %SYB_MAINT_DIR%\sybasestartup.reg
    echo "Start"=dword:00000003>> %SYB_MAINT_DIR%\sybasestartup.reg
    
    regedit /S %SYB_MAINT_DIR%\sybasestartup.reg
    
    del %SYB_MAINT_DIR%\sybasestartup.reg
    goto GEN_SCRIPT
    Model.reg (see attachment) is a model for the registerkey that will be inserted. Depending on the action, it will be completed with the proper values and servername.
    The reg-file is inserted in the registry and cleaned up.
    Code:
    REM 
    REM -------------------------------------------------------
    REM          GEN_SCRIPT
    REM -------------------------------------------------------
    :GEN_SCRIPT
    echo use master					>%SYB_TMPDIR%\shutdown.tmp
    echo go						>>%SYB_TMPDIR%\shutdown.tmp
    echo shutdown					>>%SYB_TMPDIR%\shutdown.tmp
    echo go						>>%SYB_TMPDIR%\shutdown.tmp
    goto EXEC_SCRIPT
    Echo a simple shutdown-script to a temporary scriptfile. This will be used as an inputfile for the isql-session.
    Code:
    REM -------------------------------------------------------
    REM          EXEC_SCRIPT
    REM -------------------------------------------------------
    :EXEC_SCRIPT
    isql -U%SYB_MAINT_USER% -P%SYB_MAINT_PW% -S%SYB_SERVER% -i%SYB_TMPDIR%\shutdown.tmp
    goto END
    Using the isql-tool, the temporary script file is executed, shutting down the server. You'll get an error on your dos-prompt, don't worry about that one.
    Code:
    REM -------------------------------------------------------
    REM          STARTUP_AUTO
    REM -------------------------------------------------------
    :STARTUP_AUTO
    net start SYBSQL_%SYB_SERVER%
    net start SYBSQL_%SYB_SERVER%_MS
    
    goto REGKEYSTARTUP
    If the ACTION-parameter tells the script to startup the server,
    the proper service is started (note the monitor-server-service, this one often shuts down along with the sybase-server itself).
    Code:
    REM -------------------------------------------------------
    REM          STARTUP_AUTO
    REM -------------------------------------------------------
    :REGKEYSTARTUP
    copy %SYB_MAINT_DIR%\model.reg  %SYB_MAINT_DIR%\sybasestartup.reg
    
    echo [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\SYBSQL_%SYB_SERVER%]>> %SYB_MAINT_DIR%\sybasestartup.reg
    echo "Start"=dword:00000002>> %SYB_MAINT_DIR%\sybasestartup.reg
    
    regedit /S %SYB_MAINT_DIR%\sybasestartup.reg
    
    del %SYB_MAINT_DIR%\sybasestartup.reg
    goto END
    Same as the first regfil-script, but this time it changes the value so the corresponding server will be started automatically after a reboot.
    Code:
    REM -------------------------------------------------------
    REM          NOSERVER
    REM -------------------------------------------------------
    :NOSERVER
    echo Error : Server Name is Empty!
    pause
    goto END
    
    REM -------------------------------------------------------
    REM          NOUSER
    REM -------------------------------------------------------
    :NOUSER
    echo Error : User Name is Empty!
    pause
    goto END
    
    REM -------------------------------------------------------
    REM          NOPASSWORD
    REM -------------------------------------------------------
    :NOPASSWORD
    echo Error : Password is Empty!
    pause
    goto END
    
    REM -------------------------------------------------------
    REM          NOACTION
    REM -------------------------------------------------------
    :NOACTION
    echo Error : Action is empty or incorrect.
    pause
    goto END
    
    REM -------------------------------------------------------
    REM          USAGE
    REM -------------------------------------------------------
    :USAGE
    echo Usage: "sybmaint.bat {sd_once | sd_manual | su_enable}"
    pause
    Error-handling. If any variable is empty, diplay a usage-message.
    Code:
    REM -------------------------------------------------------
    REM          END
    REM -------------------------------------------------------
    :END
    if exist %SYB_TMPDIR%\shutdown.tmp del %SYB_TMPDIR%\shutdown.tmp
    Clean up the temporary scriptfile.
    Done!
    Call the script at a dos-prompt with one of the following parameters:
    sd_manual to shutdown the server and alter the service so it won't start after a reboot of the machine.
    sd_once to only shutdown the server once. Next time the machine reboots, theservice will start again.
    su_enable starts the service and changes the service of the sybase-server so it wil start up automatically.

    I hope it is clear enough to understand, if not, don't hesitate to ask .
    Attached Files Attached Files
    I'm not crazy, I'm an aeroplane!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •