1
Using TSM Macros, Scripts andUsing TSM Macros, Scripts andSQLSQL
(Implementation and Practical Use)(Implementation and Practical Use)
Laura BuckleyLaura Buckley
Automating Daily TasksAutomating Daily Tasks
•• MacrosMacros–– Automate simple repetitive server operationsAutomate simple repetitive server operations
•• TSM SQL interfaceTSM SQL interface–– Provides access to more database information thanProvides access to more database information than
QUERYQUERY
•• TSM server scriptsTSM server scripts–– Provide a more robust method for automatingProvide a more robust method for automating
repetitive server operationsrepetitive server operations
2
Creating MacrosCreating Macros•• Enter the administrative commands in a text fileEnter the administrative commands in a text file
-- A hyphen or slash continues a lineA hyphen or slash continues a line
-- Blank lines are ignoredBlank lines are ignored
-- 256 characters per line without continuation256 characters per line without continuation
-- 1500 characters with continuation1500 characters with continuation
•• Substitution variables are allowedSubstitution variables are allowed–– Substitution variables are represented by a % and aSubstitution variables are represented by a % and a
number (i.e. %1, %2…)number (i.e. %1, %2…)
•• Comments are preceded and followed by /*Comments are preceded and followed by /*and */and */
Sample MacroSample Macro
/* /* ex tenddbextenddb..m a c m a c */*// * Th is macro wi l l add a vo lume to and extend the - * // * Th is macro wi l l add a vo lume to and extend the - * // * TSM server da tabase. * // * TSM server da tabase. * // * The var iab les a re : %1 = new vo lume name * // * The var iab les a re : %1 = new vo lume name * // * %2 = new volume s ize * // * %2 = new volume s ize * /
def ine def ine dbvol dbvol % 1 % 1 formats izeformats ize=%2 wa i t=yes=%2 wa i t=yesex tend db %2ex tend db %2
3
Executing MacrosExecuting Macros
•• At the Admin Command LineAt the Admin Command Line–– macro filename variablemacro filename variable
•• tsmtsm> macro > macro extendbextendb..macmac f:\db3. f:\db3.dsm dsm 20002000
•• In batch mode, at the OS promptIn batch mode, at the OS prompt–– dsmadmc dsmadmc –id=admin –password=–id=admin –password=pwd pwd macromacro
filename variablesfilename variables•• dsmadmcdsmadmc –id= –id=lauralaura –password=snail macro –password=snail macro
extenddbextenddb..macmac f:\db3. f:\db3.dsmdsm 2000 2000
Commit and RollbackCommit and Rollback
•• COMMIT command controls when itemsCOMMIT command controls when itemsare “committed” to the dbare “committed” to the db–– If an error while processing a macro, theIf an error while processing a macro, the
server rolls back uncommitted changesserver rolls back uncommitted changes
–– Run admin client (Run admin client (dsmadmcdsmadmc) with) withITEMCOMMIT option to commit all changesITEMCOMMIT option to commit all changes
–– Use ROLLBACK as last command to testUse ROLLBACK as last command to testmacro (with no macro (with no COMMIT’sCOMMIT’s))
4
Using the TSM SQL InterfaceUsing the TSM SQL Interface
•• Three system catalog tablesThree system catalog tables–– SYSCAT.TABLES = tables that are availableSYSCAT.TABLES = tables that are available
for queriesfor queries
–– SYSCAT.COLUMNS = columns that reside inSYSCAT.COLUMNS = columns that reside ineach tableeach table
–– SYSCAT.ENUM = legal values forSYSCAT.ENUM = legal values forenumerated data types and orders of typesenumerated data types and orders of types
Displaying the SystemDisplaying the SystemCatalogsCatalogsTSM> select TSM> select tabschematabschema, , tabnametabname,,
unique_index from unique_index from syscatsyscat_tables_tables
TSM>select TSM>select tabnametabname, , colnamecolname, , typenametypenamefrom from syscatsyscat.columns.columns
TSM>select TSM>select typenametypename, values from, values fromsyscatsyscat..enumtypesenumtypes
5
Using the TSM SQL InterfaceUsing the TSM SQL Interface
•• Basic SQL Select structureBasic SQL Select structure–– SELECT field FROM columnSELECT field FROM column
–– i.e SELECT NODE FROM SESSIONSi.e SELECT NODE FROM SESSIONS
•• Use WHERE clause to specify onlyUse WHERE clause to specify onlyspecific criteria to be metspecific criteria to be met–– select node_name from nodes whereselect node_name from nodes where
locked='YES'locked='YES'
Configuring and Using theConfiguring and Using theODBC DriverODBC Driver•• Works with Works with WinX WinX Operating SystemsOperating Systems
•• Use a spreadsheet or database app to accessUse a spreadsheet or database app to accessinformationinformation–– Select ODBC driver during setupSelect ODBC driver during setup
–– Update or copy the default TSM ODBC Data SourceUpdate or copy the default TSM ODBC Data Source•• Select Data source administrator from control panelSelect Data source administrator from control panel•• Click once on TSM ODBC Sample User DSNClick once on TSM ODBC Sample User DSN•• Click on Configure buttonClick on Configure button•• Change name of DSN to the name of the TSM ServerChange name of DSN to the name of the TSM Server•• Change server address to your TSM Server IP addressChange server address to your TSM Server IP address•• Click OKClick OK
6
Using the ODBC Driver withUsing the ODBC Driver withMS Query and MS ExcelMS Query and MS Excel
•• Open an MS Excel WindowOpen an MS Excel Window
•• Pull down the Data menuPull down the Data menu
•• Select Get external dataSelect Get external data
•• Select the TSM Server data source you created orSelect the TSM Server data source you created ormodified earliermodified earlier
•• Click OKClick OK
•• Enter a TSM Administrator/Password combinationEnter a TSM Administrator/Password combination
•• The Query Wizard will now be openThe Query Wizard will now be open
•• Select the tables you want to querySelect the tables you want to query
Creating TSM Server ScriptsCreating TSM Server Scripts
•• TSM Server TSM Server sciptsscipts are stored in the TSM are stored in the TSMServer database (not text files)Server database (not text files)
•• Can be processed interactively or inCan be processed interactively or inbatchbatch
•• Good examples are in the scripts.Good examples are in the scripts.smp smp filefile(older versions of TSM)(older versions of TSM)
7
Creating TSM Server ScriptsCreating TSM Server ScriptsContinuedContinued•• TSM Scripts can include:TSM Scripts can include:
–– Command parameter substitutionCommand parameter substitution
–– SQL SELECT statementsSQL SELECT statements
–– Conditional logical flow statements using the IFConditional logical flow statements using the IFclause and return code valuesclause and return code values
–– The EXIT statement to end processingThe EXIT statement to end processing–– The GOTO statement to direct logic flow to continueThe GOTO statement to direct logic flow to continue
with the line starting with the specifiedwith the line starting with the specified
–– Comment linesComment lines
Defining and Executing ServerDefining and Executing ServerScripts – CLI and FileScripts – CLI and FileTSM>define script q_admin_owner “selectTSM>define script q_admin_owner “select
schedule_name,chg_admin fromschedule_name,chg_admin fromadmin_schedules” description=“Display Adminadmin_schedules” description=“Display Adminschedule current owners”schedule current owners”
TSM>updated script q_admin_owner “q event * *TSM>updated script q_admin_owner “q event * *type=admin”type=admin”
Or From a FileOr From a File
TSM>define script q_admin_owner TSM>define script q_admin_owner ileile==qadminqadmin.txt.txt
8
Defining a Server Script UsingDefining a Server Script Usingthe Web Interfacethe Web Interface•• Expand Object View and AutomationExpand Object View and Automation
•• Click Server Command ScriptsClick Server Command Scripts
•• Pull Down Operation Define a new commandPull Down Operation Define a new commandscriptscript
•• Enter the Script NameEnter the Script Name
•• Enter a descriptionEnter a description
•• Enter the command lines for the scriptEnter the command lines for the script
•• Substitution VariablesSubstitution Variables–– Represented with $ followed by numberRepresented with $ followed by number
–– Select $1 from nodes where platform_name=‘$2’Select $1 from nodes where platform_name=‘$2’
•• Logic Flow StatementsLogic Flow Statements–– Test for return code values (Test for return code values (rcrc_ok, warning, error)_ok, warning, error)
–– See other return code values in Appendix C ofSee other return code values in Appendix C ofAdministrator’s ReferenceAdministrator’s Reference
Substitution & Logic Flow inSubstitution & Logic Flow inScriptsScripts
9
Example Script (fromExample Script (fromscripts.scripts.smpsmp))'/* ---------------------------------------------*/''/* ---------------------------------------------*/''/* Script Name: Q_NO_ASSOC */''/* Script Name: Q_NO_ASSOC */''/* Description: Display nodes in a policy */''/* Description: Display nodes in a policy */''/* domain that are not associated */''/* domain that are not associated */''/* with a specific schedule. */''/* with a specific schedule. */''/* Parameter 1: domain name */''/* Parameter 1: domain name */''/* Parameter 2: schedule name */''/* Parameter 2: schedule name */''/* Example: run q_no_assoc POLICY SCHEDULE */''/* Example: run q_no_assoc POLICY SCHEDULE */''/* ---------------------------------------------*/''/* ---------------------------------------------*/'"select node_name from nodes where -""select node_name from nodes where -"" domain_name=upper('$1') and node_name not in -"" domain_name=upper('$1') and node_name not in -"" (select node_name from associations where -"" (select node_name from associations where -"" domain_name=upper('$1') and -"" domain_name=upper('$1') and -"" schedule_name=upper('$2')) "" schedule_name=upper('$2')) "
Getting StartedGetting Started
•• Be sure to check out scripts.Be sure to check out scripts.smp smp (server(serverdirectory in older versions)directory in older versions)
•• Ask for help from the listservAsk for help from the listserv
•• Check SQL reference materialsCheck SQL reference materials
•• Dig in!Dig in!