~siggi-bjarnason/siggivbscript/vbscript

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
Option Explicit

Dim FileObj, strLine, fso, f, fc, f1, strOut, strParts, FolderSpec, strOutFileName, objFileOut, bRightSection, trunkname, x

If WScript.Arguments.Count <> 2 Then
  WScript.Echo "Usage: " & wscript.scriptname & " inpath, outfilename"
  WScript.Quit
End If

FolderSpec = WScript.Arguments(0)
strOutFileName = WScript.Arguments(1)

Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder(folderspec)
Set objFileOut = fso.createtextfile(strOutFileName)
Set fc = f.Files
strOut = "Device,PortChannelName,Interface" '& vbcrlf
For Each f1 in fc
	If f1.name <> strOutFileName Then
		Set FileObj = fso.opentextfile(folderspec & "\" & f1.name)
		While not fileobj.atendofstream
			strLine = Trim(FileObj.readline)
			If strline = "# '/config/bigip_base.conf' file" Then
				bRightSection = True
				'logout "Found right section in " & f1.name
			End If
			If bRightSection Then
				If Left(strline,5) = "trunk" Then
					If strOut <> "" Then
						'wscript.echo strOut
						'objFileOut.writeline strOut
						logout strout
						strout = ""
					End If
					trunkname = Left(f1.name,InStrRev(f1.name,".")-1) & "," & Mid(strline,7,Len(strline)-8)
					'logout "Found trunk: " & trunkname
				Else
					If Left(strline,9) = "interface" Then
						If trunkname <> "" Then
							strParts = split(strline," ")
							'wscript.echo "Found a interface line consisting of " & UBound(strparts) & " parts: " & strline
							'logout "Found a interface line consisting of " & UBound(strparts) & " parts: " & strline
							For x= 1 to UBound(strparts)
								strOut = strOut & trunkname & "," & strparts(x) & vbcrlf
							Next
						Else
							strParts = split(strline," ")
							If strparts(1) <> "mgmt" Then strOut = strOut & Left(f1.name,InStrRev(f1.name,".")-1) & ",n/a," & strparts(1)	& vbcrlf
						End If
					End If
				End If
				If Left(strline,4) = "vlan" Then
					brightsection = false
					'logout "Found vlan section, exiting"
					trunkname = ""
				End If
			End If
		Wend
		If strOut <> "" Then
			'wscript.echo strOut
			logout strOut
		End If
		FileObj.close
		strOut = ""
	End If
Next

objFileOut.close

Set FileObj = fso.opentextfile(strOutFileName)
strline = fileobj.readall
strline = replace(strline,vbcrlf&vbcrlf,vbcrlf)
fileobj.close

Set objFileOut = fso.createtextfile(strOutFileName)
objFileOut.write strline
objfileout.close

Set FileObj = nothing
Set objFileOut = nothing
Set fc = nothing
Set f = nothing
Set fso = nothing

Sub logout(strText)
	wscript.echo strText
	objFileOut.writeline strText
End Sub