Файл tasks.vbs
Option Explicit
Const ForReading = 1
Const fsuffix = «_failed»
Const ScriptLimit = 50, TimeOut = 15
Dim Args, oShell, fso, oHostFile, oFailHostFile
Dim aHostList(), aScripts(), aHosts(), aTimes()
Dim strScript, strHostFile, strFailHostFile, strArguments
Sub UsageBox
MsgBox «General syntax:» & vbCrLf & _
«tasks.vbs [list of arguments] ... «, _
vbOKOnly + vbInformation
End Sub
Sub ErrorBox
MsgBox «Error « & Err.Number & «: « & Err.Description, vbOKOnly + vbExclamation
Err.Clear
End Sub
Sub DoneBox
MsgBox «All done! «, vbOKOnly + vbInformation
End Sub
Sub LogFail(strHost)
oFailHostFile.WriteLine strHost
End Sub
Sub RunTasks
Dim i, n, bEmpty, intMaxScript, intMaxHostList
intMaxScript = ScriptLimit - 1
intMaxHostList = UBound(aHostList)
If intMaxHostList < intMaxScript Then intMaxScript = intMaxHostList
ReDim aScripts(intMaxHostList), aHosts(intMaxHostList), aTimes(intMaxHostList)
n = 0
For i = 0 To intMaxScript
aTimes(i) = 0
Next
bEmpty = True
Do
If Not bEmpty Then Wscript.Sleep 1000
bEmpty = True
For i = 0 To intMaxScript
If aTimes(i) = 0 Then
If n <= intMaxHostList Then
aTimes(i) = 1
aHosts(i) = aHostList(n)
Set aScripts(i) = oShell.Exec(«wscript.exe « & strScript & « « & _
aHosts(i) & strArguments)
n = n + 1
End If
ElseIf aTimes(i) = TimeOut Then
If aScripts(i).Status = 0 Then aScripts(i).Terminate
LogFail(aHosts(i))
aTimes(i) = 0
Else
If aScripts(i).Status = 0 Then
aTimes(i) = aTimes(i) + 1
Else
If aScripts(i).ExitCode <> 0 Then LogFail(aHosts(i))
aTimes(i) = 0
End If
End If
If aTimes(i) > 0 Then bEmpty = False
Next
Loop Until bEmpty
End Sub
Sub ProcFiles
Dim i, strHost, errRun
On Error Resume Next
errRun = oShell.Run(«wscript.exe « & strScript, 0, True)
If errRun = 9 Then
Set fso = CreateObject(«Scripting.FileSystemObject»)
Set oHostFile = fso.OpenTextFile(strHostFile, ForReading, False)
If Err.Number = 0 Then
Set oFailHostFile = fso.CreateTextFile(strFailHostFile, True)
If Err.Number = 0 Then
i = 0
Do Until oHostFile.AtEndOfStream
strHost = oHostFile.ReadLine
If Len(strHost) > 0 Then
ReDim Preserve aHostList(i)
aHostList(i) = strHost
i = i + 1
End If
Loop
oHostFile.Close
If i > 0 Then RunTasks
oFailHostFile.Close
DoneBox
Else
ErrorBox
End If
Else
ErrorBox
End If
End If
End Sub
Dim i, lenH, dotH
Set Args = Wscript.Arguments
If Args.Count > 1 Then
strScript = Args(0)
strHostFile = Args(1)
strArguments = «»
For i = 2 To Args.Count - 1
strArguments = strArguments & « « & Args(i)
Next
dotH = InStrRev(strHostFile, «.»)
lenH = Len(strHostFile)
If dotH = 0 Then
strFailHostFile = strHostFile & fsuffix
Else
strFailHostFile = Left(strHostFile, dotH - 1) & fsuffix & _
Right(strHostFile, lenH - dotH +1)
End If
Set oShell = WScript.CreateObject(«WScript.Shell»)
ProcFiles
Else
UsageBox
End If