Login | |
|
 |
Running command lines with WshShell/oShell.Run - 6/13/2006 2:49:15 AM
|
|
 |
|
| |
brewei
Posts: 1
Score: 0
Joined: 6/13/2006
Status: offline
|
I've got a VBScript I've been working on the last few days that automates config backups for my server environment. The general jist is that it runs on one of four DSMs, queries a SQL DB for handled servers based on which DSM it's running on, and then for each server returned runs a command on the DSM that queries the handled server and writes the output to a third, central server. Whew, that was a mouthful. Anyway, the problem I'm having is that, while the initial SQL query (input as a command using WshShell.Run) fires just fine, the later command doesn't execute. It doesn't return an error code, and to make sure it wasn't a simple formatting glitch I echoed the command that was being run, input it manually into the command prompt, and the command worked fine. I've included my script below for reference, but it seems as though this is a problem of theory more than one of script. If I can run my commands interactively, but not automated as a batch, what might I be doing wrong? Any help here is appreciated. Const OverwriteExisting = True Const ForReading = 1 Set objFSO = CreateObject("Scripting.FileSystemObject") Set WshShell = WScript.CreateObject("WScript.Shell") Set WshNetwork = WScript.CreateObject("WScript.Network") Set objLog = objFSO.CreateTextFile("C:\mkconfiglog.log") strDSM = WshNetwork.ComputerName objLog.WriteLine "Beginning mkconfig backup process on " & strDSM & "..." 'Determines which DSM the script is running on and runs the appropriate SQL DB query Select Case LCase(Left(strDSM, 6)) Case "pssrdc" strSQL = "isql -S PSMRDC04 -U tngsa -P tngadmin -d TNGDB -Q ""select substring(name,1,12) from tng_managedobject where DSM_Server like 'PSSRDC%' and class_name like 'Window%'"" -o c:\dsmlist.txt" objLog.WriteLine "Running PSSRDC query..." WScript.Echo "Using PSSRDC SQL query" Case "dssrdc" strSQL = "isql -S PSMRDC04 -U tngsa -P tngadmin -d TNGDB -Q ""select substring(name,1,12) from tng_managedobject where DSM_Server like 'DSSRDC%' and class_name like 'Window%'"" -o c:\dsmlist.txt" objLog.WriteLine "Running DSSRDC query..." WScript.Echo "Using DSSRDC SQL query" Case "psmrdx" strSQL = "isql -S PSMRDC04 -U tngsa -P tngadmin -d TNGDB -Q ""select substring(name,1,12) from tng_managedobject where DSM_Server like 'PSMRDX%' and class_name like 'Window%'"" -o c:\dsmlist.txt" objLog.WriteLine "Running PSMRDX query..." WScript.Echo "Using PSMRDX SQL query" Case Else 'Includes PSMRDC strSQL = "isql -S PSMRDC04 -U tngsa -P tngadmin -d TNGDB -Q ""select substring(name,1,12) from tng_managedobject where DSM_Server like 'PSMRDC%' and class_name like 'Window%'"" -o c:\dsmlist.txt" objLog.WriteLine "Running PSMRDC query..." WScript.Echo "Using PSMRDC SQL query" End Select WshShell.Run(strSQL) Set objReadDSM = objFSO.OpenTextFile("C:\dsmlist.txt", ForReading) strServers = objReadDSM.ReadAll arrServers = Split(strServers, vbNewLine) WScript.Echo "A total of " & UBound(arrServers) - 4 & " servers in query." 'Attempts to run the CA Unicenter "mkconfig" command for each of these servers. This is where the problem is happening. For Each strServer In arrServers strServer = Trim(strServer) If strServer <> "" And Left(strServer, 5) <> "-----" And Left(strServer, 1) <> "(" Then WScript.Echo "Running on server " & strServer objLog.WriteLine "Running mkconfig on " & strServer & "..." 'Reformatting current date and time for file name structure arrDate = Split(Date, "/") strDate = arrDate(2) & arrDate(0) & arrDate(1) arrTime = Split(Time, ":") If Len(arrTime(0)) < 2 Then arrTime(0) = "0" & arrTime(0) If Right(arrTime(2), 2) = "PM" Then arrTime(0) = arrTime(0) + 12 If arrTime(0) = 12 And Right(arrTime(2), 2) = "AM" Then arrTime(0) = "00" strTime = arrTime(0) & arrTime(1) 'Define command strings strWinCommand = "mkconfig caiW2kOs@" & strServer & " > (File Path to central server)" & strDate & "_" & strTime & "_" & strServer & "_caiW2kOs.cfg" strLogCommand = "mkconfig caiLogA2@" & strServer & " > (File Path to central server)" & strDate & "_" & strTime & "_" & strServer & "_caiLogA2.cfg" WScript.Echo strWinCommand WScript.Echo strLogCommand 'Attempt to run command strings WshShell.Run(strWinCommand) WshShell.Run(strLogCommand) intCounter = intCounter + 1 End If Next objLog.WriteLine "Complete! Configurations For " & intCounter & " servers backed up." WScript.Echo "Complete! Configurations For " & intCounter & " servers backed up."
|
|
| |
|
|
|
|
|