Batch/Vbs script that can run this line of code and log the success/Failure.

Hi,

Batch script that can run this line of code and log the success/Failure.
I need to run the below line of 1000's of users where just the xml file name and the email address at the end will change. I have the below lines ready for 1000's of users
Dbimpexp.exe /hrxmlfile:"c:\sharath.yui.xml" /user:sharath.yui@plc.com

All in 1 file. Now need help with a batch script when run executes one after the other and logs the results.
i get results as this for each line

Dbimpexp.exe /hrxmlfile:"c:\sharath.yui.xml" /user:sharath.yui@plc.com
dbVersion: 4
User Data Schema Version : 4
Exporting 1 Homed Resource(s) from database...
100% complete.
Export completed successfully.

I want the last line alone to be placed with the email address to a txt file. So at the end of running i know if all were successful or any failed.

Can anyone help with a vbs or batch script that can run all the lines and log the results.

Regards
Sharath
LVL 11
bsharathAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

vb_studentCommented:
you need to use the file system object you can find info about this here
0
RobSampsonCommented:
Hi Sharath, try this.

Regards,

Rob.
strInputFile = "commands.bat"
strLogFile = "log.txt"
strTempOutput = GetFolder(Replace(WScript.ScriptFullName, WScript.ScriptName, "")).ShortPath & "\TempOutput.txt"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Const intForReading = 1
Set objShell = CreateObject("WScript.Shell")
strPSExec = objFSO.GetFile(strPSExec).ShortPath
Set objInput = objFSO.OpenTextFile(strInputFile, intForReading, False)
Set objLog = objFSO.CreateTextFile(strLogFile, True)
While Not objInput.AtEndOfStream
	strCommand = objInput.ReadLine
	If Trim(strCommand) <> "" Then
		strEmail = Mid(strCommand, InStrRev(strCommand, ":") + 1)
		If objFSO.FileExists(strTempOutput) = True Then objFSO.DeleteFile strTempOutput
		strCommand = "cmd /c " & strCommand & " > " & strTempOutput
		objShell.Run strCommand, 0, True
		strStatus = ""
		If objFSO.FileExists(strTempOutput) = True Then
			Set objTemp = objFSO.OpenTextFile(strTempOutput, intForReading, False)
			While Not objTemp.AtEndOfStream
				strStatus = objTemp.ReadLine
			Wend
			objTemp.Close
			objLog.WriteLine strEmail & "," & strStatus
		Else
			objLog.WriteLine strEmail & ",No output was created."
		End If
	End If
Wend
objInput.Close
objLog.Close
MsgBox "Done. Please see " & strLogFile

Open in new window

0
bsharathAuthor Commented:
Thanks Rob should i have all the 100's of users lines
Dbimpexp.exe /hrxmlfile:"c:\sharath.yui.xml" /user:sharath.yui@plc.com
In the bat file?
0
JavaScript Best Practices

Save hours in development time and avoid common mistakes by learning the best practices to use for JavaScript.

RobSampsonCommented:
Yes, it will just treat that as a text file, and read the lines from it, and not execute the whole batch file in one go.

Rob.
0
bsharathAuthor Commented:
Rob i get this

C:\>cscript Change_OCS_XML_Data.vbs
Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.

C:\Change_OCS_XML_Data.vbs(3, 1) Microsoft VBScript runtime error: Type mismatch
: 'GetFolder'
0
RobSampsonCommented:
Oh whoops....

Try this.
Set objFSO = CreateObject("Scripting.FileSystemObject")
strInputFile = "commands.bat"
strLogFile = "log.txt"
strTempOutput = objFSO.GetFolder(Replace(WScript.ScriptFullName, WScript.ScriptName, "")).ShortPath & "\TempOutput.txt"
Const intForReading = 1
Set objShell = CreateObject("WScript.Shell")
strPSExec = objFSO.GetFile(strPSExec).ShortPath
Set objInput = objFSO.OpenTextFile(strInputFile, intForReading, False)
Set objLog = objFSO.CreateTextFile(strLogFile, True)
While Not objInput.AtEndOfStream
	strCommand = objInput.ReadLine
	If Trim(strCommand) <> "" Then
		strEmail = Mid(strCommand, InStrRev(strCommand, ":") + 1)
		If objFSO.FileExists(strTempOutput) = True Then objFSO.DeleteFile strTempOutput
		strCommand = "cmd /c " & strCommand & " > " & strTempOutput
		objShell.Run strCommand, 0, True
		strStatus = ""
		If objFSO.FileExists(strTempOutput) = True Then
			Set objTemp = objFSO.OpenTextFile(strTempOutput, intForReading, False)
			While Not objTemp.AtEndOfStream
				strStatus = objTemp.ReadLine
			Wend
			objTemp.Close
			objLog.WriteLine strEmail & "," & strStatus
		Else
			objLog.WriteLine strEmail & ",No output was created."
		End If
	End If
Wend
objInput.Close
objLog.Close
MsgBox "Done. Please see " & strLogFile

Open in new window

0
bsharathAuthor Commented:
I get this
C:\>cscript Change_OCS_XML_Data.vbs
Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.

C:\Change_OCS_XML_Data.vbs(7, 1) Microsoft VBScript runtime error: Invalid procedure call or argument
0
RobSampsonCommented:
Oh, line 7 doesn't need to be there....I thought it did for this one, but then I re-read what you need...
Set objFSO = CreateObject("Scripting.FileSystemObject")
strInputFile = "commands.bat"
strLogFile = "log.txt"
strTempOutput = objFSO.GetFolder(Replace(WScript.ScriptFullName, WScript.ScriptName, "")).ShortPath & "\TempOutput.txt"
Const intForReading = 1
Set objShell = CreateObject("WScript.Shell")
Set objInput = objFSO.OpenTextFile(strInputFile, intForReading, False)
Set objLog = objFSO.CreateTextFile(strLogFile, True)
While Not objInput.AtEndOfStream
	strCommand = objInput.ReadLine
	If Trim(strCommand) <> "" Then
		strEmail = Mid(strCommand, InStrRev(strCommand, ":") + 1)
		If objFSO.FileExists(strTempOutput) = True Then objFSO.DeleteFile strTempOutput
		strCommand = "cmd /c " & strCommand & " > " & strTempOutput
		objShell.Run strCommand, 0, True
		strStatus = ""
		If objFSO.FileExists(strTempOutput) = True Then
			Set objTemp = objFSO.OpenTextFile(strTempOutput, intForReading, False)
			While Not objTemp.AtEndOfStream
				strStatus = objTemp.ReadLine
			Wend
			objTemp.Close
			objLog.WriteLine strEmail & "," & strStatus
		Else
			objLog.WriteLine strEmail & ",No output was created."
		End If
	End If
Wend
objInput.Close
objLog.Close
MsgBox "Done. Please see " & strLogFile

Open in new window

0
bsharathAuthor Commented:
Rob in the log i get just the email address
0
RobSampsonCommented:
When you run this for one of the lines, directly from a command prompt:

Dbimpexp.exe /hrxmlfile:"c:\sharath.yui.xml" /user:sharath.yui@plc.com > tempfile.txt

and then open the tempfile.txt in notepad, is there a blank line at the end?

If so, then try the code below.  If the code doesn't work, can you please post the tempfile.txt that the above command created?

Rob.
Set objFSO = CreateObject("Scripting.FileSystemObject")
strInputFile = "commands.bat"
strLogFile = "log.txt"
strTempOutput = objFSO.GetFolder(Replace(WScript.ScriptFullName, WScript.ScriptName, "")).ShortPath & "\TempOutput.txt"
Const intForReading = 1
Set objShell = CreateObject("WScript.Shell")
Set objInput = objFSO.OpenTextFile(strInputFile, intForReading, False)
Set objLog = objFSO.CreateTextFile(strLogFile, True)
While Not objInput.AtEndOfStream
	strCommand = objInput.ReadLine
	If Trim(strCommand) <> "" Then
		strEmail = Mid(strCommand, InStrRev(strCommand, ":") + 1)
		If objFSO.FileExists(strTempOutput) = True Then objFSO.DeleteFile strTempOutput
		strCommand = "cmd /c " & strCommand & " > " & strTempOutput
		objShell.Run strCommand, 0, True
		strStatus = ""
		If objFSO.FileExists(strTempOutput) = True Then
			Set objTemp = objFSO.OpenTextFile(strTempOutput, intForReading, False)
			While Not objTemp.AtEndOfStream
				strTempLine = objTemp.ReadLine
				If Trim(strTempLine) <> "" Then strStatus = objTemp.ReadLine
			Wend
			objTemp.Close
			objLog.WriteLine strEmail & "," & strStatus
		Else
			objLog.WriteLine strEmail & ",No output was created."
		End If
	End If
Wend
objInput.Close
objLog.Close
MsgBox "Done. Please see " & strLogFile

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
bsharathAuthor Commented:
I get this in the tmp file

C:\>Dbimpexp.exe /import /hrxmlfile:"c:\sharath.ss.xml" /user:sharath.ss@group.com
dbVersion: 26
User Data Schema Version : 21
Importing Homed Resources into database...

1 Homed Resource(s) imported.
Import completed successfully.

I tried the 2nd code i get this

C:\Change_OCS_XML_Data.vbs(21, 37) Microsoft VBScript runtime error: Input past end of file
0
RobSampsonCommented:
Oh sorry, change this line
                        If Trim(strTempLine) <> "" Then strStatus = objTemp.ReadLine


to this
                        If Trim(strTempLine) <> "" Then strStatus = strTempLine

Rob.
0
bsharathAuthor Commented:
Thanks Rob works perfect
Any help with this
http://www.experts-exchange.com/Programming/Languages/Q_25974591.html
0
bsharathAuthor Commented:
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming Languages-Other

From novice to tech pro — start learning today.