Quantcast
Channel: Tech Support Guy
Viewing all articles
Browse latest Browse all 38405

VBScript Automation Problem

$
0
0
Hi everyone,

I am trying to automate a consolidation process on the server.

The current process uses VB Script to start a SQL server consolidation.

I am simply trying to pass the values to the script with an array and a loop.

The two scripts follow, the first is the working code snippet and the second is the non-working example.
(Each consolidation uses a text based requirements file which I have not included as they just list variables. eg. "ConsolText.req")

______________________________________________________________

##########################################
WORKING FORMULA
##########################################
Code:

Dim obScript
Set obScript = CreateObject("csscript.script")
resp = obScript.ExecuteRequestFile("localhost","3013","BPENG","ConsolText.req")
msgbox "Done"


##########################################
MY REVISED FORMULA
##########################################
Code:

'--------------------------------------------------------------------
'  Create a FSO object and open the file by providing the file path
'--------------------------------------------------------------------
        Dim fso, f, filePath, fileName, line, theText, theChar, CONSOLS, ASPORT, APPSERVER, EMAILS
        fileName = "ConsolInput.txt"
        filePath = Replace(WScript.ScriptFullName, WScript.ScriptName, "")
        filePath = filePath & fileName
        Set fso = CreateObject("Scripting.FileSystemObject")
        Set f = fso.OpenTextFile(filePath)

'--------------------------------------------------------------
'  Loop through the Variables file assigning values to memory
'--------------------------------------------------------------

        'Line 1 - (No Data)
        f.readline()
        'Line 2 - Consolidations
        theText = f.readline()
        theChar = InStr (theText, ":")+1
        theText = mid(theText,theChar,999)
        CONSOLS = split(theText, ",")
        'Line 3 - Application Server Port
        theText = f.readline()
        theChar = InStr (theText, ":")+1
        ASPORT = cint(mid(theText,theChar,999))
        'Line 4 - Application Server Name
        theText = f.readline()
        theChar = InStr (theText, ":")+1
        APPSERVER = trim(mid(theText,theChar,999))
        'Line 5 - People to Email
        theText = f.readline()
        theChar = InStr (theText, ":")+1
        theText = mid(theText,theChar,999)
        EMAILS = split(theText, ",")
        'Close the text file
        f.Close
       
'-----------------------------------------------------
'  Perform Consolidations
'-----------------------------------------------------

        Dim obScript

        for line = 0 to UBound(CONSOLS)
                theText = trim(CONSOLS(line)) & ".req"
                Set obScript = CreateObject("csscript.script")
                resp = obScript.ExecuteRequestFile(APPSERVER,ASPORT,"BPENG",theText)
        Next

##########################################
USER DEFINED VARIABLES - ("ConsolInput.txt")
##########################################

Code:

------------------------------------------------------------
1. Consolidations            : ConsolText, ConsolGlobDriv
2. Application Server Port  : 3013
3. Application Server        : localhost
4. Email Addresses to Notify : john.ortt, jonathan.webb
------------------------------------------------------------

______________________________________________________________

I would appreciate any help anyone can provide,

Thanks and regards,

John Ortt

Viewing all articles
Browse latest Browse all 38405

Trending Articles