Step 1: Create a VBS wrapper
To execute a VB Script, you need to create a batch wrapper to the vbscript. To make this wrapper useful to future vbscripts, let us make it generic enough to execute any given VB Script. Here is the batch wrapper (/apps/Tivoli/scripts/vbsexec.bat).
@echo off
REM /apps/Tivoli/scripts/vbsexec.bat
REM Batch script to execute a VBS file
cscript.exe //nologo %1
exit %ERRORlEVEL%
The above script accepts a vbscript name as argument, executes the script and exits with the whatever error code that the script returned.
Step 2: Create a Tivoli task
Now, let us create a Tivoli task to execute the above batch command.
wcrttask -t Vbsexec.task -l Tivoli-Tasks -r admin -i w32-ix86 `hostname` /apps/Tivoli/scripts/vbsexec.bat -u '*' -g '*'
Step 3: Create dependency if needed
Is the vbscript already available on the endpoint? If so, you can skip this step and heave a big sigh of relief. If you need to copy down the VBscript to the endpoint, you need to do create a Framework dependency. First, on the TMR, create a directory to store your VB Scripts under "$BINDIR/.." and copy the vbscript there.
$ mkdir $BINDIR/../vbs
$ cp /some/path/test.vbs $BINDIR/../vbs
Note: You have to maintain the above directory structure on all your gateways to which your endpoints will be connected. If you have large number of gateways, you may want to use the remote file copy program such as gbscp. Please see this article about gbscp.
Create a dependecy set and make your vbscript as part of dependency set. This will copy the vbscript to your C:\Program Files\Tivoli\lcf\scripts directory.
wdepset -c vbs-depset -a w32-ix86 ../vbs/test.vbs +p %IBASE%/scripts
Tivoli Tasks uses the task-lcf-base as the base dependency set, we need to make this depedency set as a subset of our vbs-depset so that any basic task dependencies will be honored when we execute them.
wdepset -e @DependencyMgr:vbs_depset -a depset `wlookup -r DependencyMgr task-lcf-base`
Tivoli uses the run_task method (as you can see from odstat output) to run the given task on an endpoint/managed node. We need to associate our vbs_depset with this method, so that whenever the run_task method is invoked, the dependency set will be activated.
wchdep @Classes:TaskEndpoint @DependencyMgr:vbs_depset run_task
Synchronize your gateways.wgateway
Step 4:Now execute the task
While executing a task, specify the name of the script to execute in the argument to the task like below. Remember your vbscripts will be copied to %LCFROOT%/vbs directory.
wruntask -t Vbsexec.task -l Tivoli-Tasks -h @Endpoint:ep1 -a "C:/progra\1/Tivoli/lcf/vbs/test.vbs"
Tuesday, March 11, 2008
Executing a VB script from Tivoli tasks
In Windows, Tivoli tasks could natively execute .EXE, .CMD and .BAT files only.. Vbscript files (.vbs), though could be natively executed in Windows Command prompt, can not be executed from Tivoli tasks directly. However, there is a way to get around this issue and this article explains how.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment