- Hands-Off Deployment of SQL Server
- Beginning Our Script
- Setting Up the Variables for Our Main Script
- Completing Our Script
- Summary
Setting Up the Variables for Our Main Script
The next step in our script is to initialize the variables required for our subscript. Later on, you will see that we use the same variables again and again within other subscripts, so any common variables (ones used in more than one script that still persist the same values) we initialize first; then the other variables that the subscript requires, we initialize right before we call our script. Table 3.1 lists the common variables that we have (and I envision) so far.
Table 3.1 Common Shared Variables for All Script within the Program
Variable Name |
Description |
AppShare |
Tells the scripts where they can find the installation media. |
DriveLetter |
Specifies the drive letter to map for the install process. |
MainLogFile |
The log file for the Main.bat script. This is purposely kept separate from the other logs. |
ScriptDir |
Specifies where the scripts are. |
ScriptName |
The name of the script that is currently being executed. |
SQLPath |
The path to where the SQL Server program files will be installed. |
SQLCollation |
The collation order of the data pages of SQL Server. |
CompanyName |
The company name that SQL Server is registered to. |
InstanceName |
The named instance of SQL Server. We will use MSSQLSERVER, which is the default instance. |
As you can see, there are a number of variables we share among the different scripts, and you will probably spot some more when we install SQL Server 2000 SP2.
Okay, so now our script begins to look like Listing 3.2.
Listing 3.2 Initializing the Common Variables within our Main Script.
:Main REM Set all the variables local to this script. setlocal REM Set up the parameters required to map a network drive to the REM share that has the SQL Server installation media set appshare=\\<machinename>\<dir> set driveletter=Y: REM Set up the logging for the script REM NOTE: This log file is purposely kept separate from the other log files set MainLogFile=%TEMP%\main.log REM Set the directory that the scripts reside in set scriptdir=%SYSTEMDRIVE%\Personal set scriptname=main.bat REM Set up the common parameters for all our scripts set SQLPath=%PROGRAMFILES%\Microsoft SQL Server\MSSQL set SQLCollation=SQL_Latin1_General_CP1_CI_AS set CompanyName=Microsoft set InstanceName=MSSQLSERVER
Now we need to simply initialize the variables that are required just for our first script (InstallSQLServer.bat); your code should look similar to Listing 3.3.
Listing 3.3 Initializing the Specific Variables Required by InstallSQLServer.bat.
REM Set up the parameters required for our sub script set SQLDataPath=%PROGRAMFILES%\Microsoft SQL Server\MSSQL\Data set SvcActDom=MSFT set SvcActName=ServiceSQL set SvcActPwd=097f738fb19d058f27b5 set SQLsaPwd=password set TCPPort=1433 set AppPath=%driveletter%\sql2k\x86\setup set ISSDir=%TEMP% set LogFile=%TEMP%\SQLInstall.log
Pretty simple so far isn't it? But that's the whole idea! The more complex the script(s), the harder it is to maintain them. Invest in a good script editor (I use EditPlus, a nice lightweight script editor); use comments well, and keep in mind the KISS (Keep It Simple, Stupid) principle.