Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Running command lines with WshShell/oShell.Run

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,35380
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Running command lines with WshShell/oShell.Run
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 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."
 
 
Post #: 1
 
 RE: Running command lines with WshShell/oShell.Run - 6/13/2006 2:57:29 AM   
  ehvbs

 

Posts: 2171
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
Hi brewei,

this

   strWinCommand = "mkconfig caiW2kOs@" & strServer & " > (File Path to central server)" & strDate & "_" & strTime & "_" & strServer & "_caiW2kOs.cfg"

looks like device rerouting (>), and you need a shell for that:

    strWinCommand = "%comspec% /c mkconfig caiW2kOs@" & strServer & " > (File Path to central server)" & strDate & "_" & strTime & "_" & strServer & "_caiW2kOs.cfg"

I'm not sure, whether you have to use WShell.ExpandEnvironmentString(s?) on strWinCommand before the .Run.

(in reply to brewei)
 
 
Post #: 2
 
 RE: Running command lines with WshShell/oShell.Run - 6/13/2006 4:45:00 AM   
  DiGiTAL.SkReAM


Posts: 1183
Score: 7
Joined: 9/6/2005
From: Florida, USA
Status: offline
No.


      

That would leave you with a  list of all the folders in the root of c: in a text file named folderlist.txt.


_____________________________

"Would you like to touch my monkey?" - Dieter (Mike Meyers)

"It is better to die like a tiger, than to live like a pussy."
-Master Wong, from Balls of Fury

(in reply to ehvbs)
 
 
Post #: 3
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Running command lines with WshShell/oShell.Run Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts