Welcome to the VanDyke Software Forums

Join the discussion today!


Go Back   VanDyke Software Forums > Scripting

Notices

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 01-23-2019, 03:51 PM
BjoernH BjoernH is offline
Registered User
 
Join Date: Mar 2018
Posts: 55
Getting VBScript runtime error: Object not a collection

Good day.

My vbscript is supposed to log into a number of Linux servers based the type of command(3) and type(2) of remote host. The problem comes in when the script has to choose a vHost array from 4 possible arrays that have been declared.

The script fails at line 307, with a runtime error: "Object is not a collection".

Code:
'#$language = "VBScript"
'#$interface = "1.0"

crt.Screen.Synchronous = True


'Create arrays for VMs
Dim arrStopStandalone(49)
	arrStopStandalone(0)= "192.168.210.20"
	arrStopStandalone(1)= "192.168.210.21"
	arrStopStandalone(2)= "192.168.210.22"
	arrStopStandalone(3)= "192.168.210.23"
	arrStopStandalone(4)= "192.168.210.24"
	arrStopStandalone(5)= "192.168.210.25"
	arrStopStandalone(6)= "192.168.210.26"
	arrStopStandalone(7)= "192.168.210.27"
	arrStopStandalone(8)= "192.168.210.28"
	arrStopStandalone(9)= "192.168.210.29"
	arrStopStandalone(10) = "192.168.210.30"
	arrStopStandalone(11) = "192.168.210.31"
	arrStopStandalone(12) = "192.168.210.32"
	arrStopStandalone(13) = "192.168.210.33"
	arrStopStandalone(14) = "192.168.210.34"
	arrStopStandalone(15) = "192.168.210.35"
	arrStopStandalone(16) = "192.168.210.36"
	arrStopStandalone(17) = "192.168.210.37"
	arrStopStandalone(18) = "192.168.210.38"
	arrStopStandalone(19) = "192.168.210.39"
	arrStopStandalone(20) = "192.168.210.40"
	arrStopStandalone(21) = "192.168.210.41"
	arrStopStandalone(22) = "192.168.210.42"
	arrStopStandalone(23) = "192.168.210.43"
	arrStopStandalone(24) = "192.168.210.44"
	arrStopStandalone(25) = "192.168.210.45"
	arrStopStandalone(26) = "192.168.210.46"
	arrStopStandalone(27) = "192.168.210.47"
	arrStopStandalone(28) = "192.168.210.48"
	arrStopStandalone(29) = "192.168.210.49"
	arrStopStandalone(30) = "192.168.210.50"
	arrStopStandalone(31) = "192.168.210.51"
	arrStopStandalone(32) = "192.168.210.52"
	arrStopStandalone(33) = "192.168.210.53"
	arrStopStandalone(34) = "192.168.210.12"
	arrStopStandalone(35) = "192.168.210.13"
	arrStopStandalone(36) = "192.168.210.14"
	arrStopStandalone(37) = "192.168.210.15"
	arrStopStandalone(38) = "192.168.210.16"
	arrStopStandalone(39) = "192.168.210.17"
	arrStopStandalone(40) = "192.168.210.18"
	arrStopStandalone(41) = "192.168.210.19"
	arrStopStandalone(42) = "192.168.210.5"
	arrStopStandalone(43) = "192.168.210.6"
	arrStopStandalone(44) = "192.168.210.8"
	arrStopStandalone(45) = "192.168.210.9"
	arrStopStandalone(46) = "192.168.210.140"
	arrStopStandalone(47) = "192.168.210.141"
	arrStopStandalone(48) = "192.168.210.142"

Dim arrStartStandalone(49)
	arrStartStandalone(0) = "192.168.210.140"
	arrStartStandalone(1) = "192.168.210.141"
	arrStartStandalone(2) = "192.168.210.142"
	arrStartStandalone(3) = "192.168.210.5"
	arrStartStandalone(4) = "192.168.210.6"
	arrStartStandalone(5) = "192.168.210.8"
	arrStartStandalone(6) = "192.168.210.9"
	arrStartStandalone(7) = "192.168.210.12"
	arrStartStandalone(8) = "192.168.210.13"
	arrStartStandalone(9) = "192.168.210.14"
	arrStartStandalone(10) = "192.168.210.15"
	arrStartStandalone(11) = "192.168.210.16"
	arrStartStandalone(12) = "192.168.210.17"
	arrStartStandalone(13) = "192.168.210.18"
	arrStartStandalone(14) = "192.168.210.19"
	arrStartStandalone(15) = "192.168.210.20"
	arrStartStandalone(16) = "192.168.210.21"
	arrStartStandalone(17) = "192.168.210.22"
	arrStartStandalone(18) = "192.168.210.23"
	arrStartStandalone(19) = "192.168.210.24"
	arrStartStandalone(20) = "192.168.210.25"
	arrStartStandalone(21) = "192.168.210.26"
	arrStartStandalone(22) = "192.168.210.27"
	arrStartStandalone(23) = "192.168.210.28"
	arrStartStandalone(24) = "192.168.210.29"
	arrStartStandalone(25) = "192.168.210.30"
	arrStartStandalone(26) = "192.168.210.31"
	arrStartStandalone(27) = "192.168.210.32"
	arrStartStandalone(28) = "192.168.210.33"
	arrStartStandalone(29) = "192.168.210.34"
	arrStartStandalone(30) = "192.168.210.35"
	arrStartStandalone(31) = "192.168.210.36"
	arrStartStandalone(32) = "192.168.210.37"
	arrStartStandalone(33) = "192.168.210.38"
	arrStartStandalone(34) = "192.168.210.39"
	arrStartStandalone(35) = "192.168.210.40"
	arrStartStandalone(36) = "192.168.210.41"
	arrStartStandalone(37) = "192.168.210.42"
	arrStartStandalone(38) = "192.168.210.43"
	arrStartStandalone(39) = "192.168.210.44"
	arrStartStandalone(40) = "192.168.210.45"
	arrStartStandalone(41) = "192.168.210.46"
	arrStartStandalone(42) = "192.168.210.47"
	arrStartStandalone(43) = "192.168.210.48"
	arrStartStandalone(44) = "192.168.210.49"
	arrStartStandalone(45) = "192.168.210.50"
	arrStartStandalone(46) = "192.168.210.51"
	arrStartStandalone(47) = "192.168.210.52"
	arrStartStandalone(48) = "192.168.210.53"

Dim arrStartCore(71)
	arrStartCore(0) = "192.168.210.140"
	arrStartCore(1) = "192.168.210.141"
	arrStartCore(2) = "192.168.210.142"
	arrStartCore(3) = "192.168.210.5"
	arrStartCore(4) = "192.168.210.6"
	arrStartCore(5) = "192.168.210.143"
	arrStartCore(6) = "192.168.210.144"
	arrStartCore(7) = "192.168.210.8"
	arrStartCore(8) = "192.168.210.9"
	arrStartCore(9) = " 192.168.210.12"
	arrStartCore(10) = "192.168.210.13"
	arrStartCore(11) = "192.168.210.14"
	arrStartCore(12) = "192.168.210.15"
	arrStartCore(13) = "192.168.210.16"
	arrStartCore(14) = "192.168.210.17"
	arrStartCore(15) = "192.168.210.18"
	arrStartCore(16) = "192.168.210.19"
	arrStartCore(17) = "192.168.210.20"
	arrStartCore(18) = "192.168.210.21"
	arrStartCore(19) = "192.168.210.22"
	arrStartCore(20) = "192.168.210.23"
	arrStartCore(21) = "192.168.210.24"
	arrStartCore(22) = "192.168.210.25"
	arrStartCore(23) = "192.168.210.26"
	arrStartCore(24) = "192.168.210.27"
	arrStartCore(25) = "192.168.210.28"
	arrStartCore(26) = "192.168.210.29"
	arrStartCore(27) = "192.168.210.30"
	arrStartCore(28) = "192.168.210.31"
	arrStartCore(29) = "192.168.210.32"
	arrStartCore(30) = "192.168.210.33"
	arrStartCore(31) = "192.168.210.34"
	arrStartCore(32) = "192.168.210.35"
	arrStartCore(33) = "192.168.210.36"
	arrStartCore(34) = "192.168.210.37"
	arrStartCore(35) = "192.168.210.38"
	arrStartCore(36) = "192.168.210.39"
	arrStartCore(37) = "192.168.210.40"
	arrStartCore(38) = "192.168.210.41"
	arrStartCore(39) = "192.168.210.42"
	arrStartCore(40) = "192.168.210.43"
	arrStartCore(41) = "192.168.210.44"
	arrStartCore(42) = "192.168.210.45"
	arrStartCore(43) = "192.168.210.46"
	arrStartCore(44) = "192.168.210.47"
	arrStartCore(45) = "192.168.210.48"
	arrStartCore(46) = "192.168.210.49"
	arrStartCore(47) = "192.168.210.50"
	arrStartCore(48) = "192.168.210.51"
	arrStartCore(49) = "192.168.210.52"
	arrStartCore(50) = "192.168.210.53"
	arrStartCore(51) = "192.168.210.54"
	arrStartCore(52) = "192.168.210.55"
	arrStartCore(53) = "192.168.210.56"
	arrStartCore(54) = "192.168.210.57"
	arrStartCore(55) = "192.168.210.58"
	arrStartCore(56) = "192.168.210.59"
	arrStartCore(57) = "192.168.210.60"
	arrStartCore(58) = "192.168.210.61"
	arrStartCore(59) = "192.168.210.62"
	arrStartCore(60) = "192.168.210.63"
	arrStartCore(61) = "192.168.210.64"
	arrStartCore(62) = "192.168.210.65"
	arrStartCore(63) = "192.168.210.66"
	arrStartCore(64) = "192.168.210.67"
	arrStartCore(65) = "192.168.210.68"
	arrStartCore(66) = "192.168.210.69"
	arrStartCore(67) = "192.168.210.70"
	arrStartCore(68) = "192.168.210.71"
	arrStartCore(69) = "192.168.210.72"
	arrStartCore(70) = "192.168.210.73"

Dim arrStopCore(71)
	arrStopCore(0) = "192.168.210.20"
	arrStopCore(1) = "192.168.210.21"
	arrStopCore(2) = "192.168.210.22"
	arrStopCore(3) = "192.168.210.23"
	arrStopCore(4) = "192.168.210.24"
	arrStopCore(5) = "192.168.210.25"
	arrStopCore(6) = "192.168.210.26"
	arrStopCore(7) = "192.168.210.27"
	arrStopCore(8) = "192.168.210.28"
	arrStopCore(9) = "192.168.210.29"
	arrStopCore(10) = "192.168.210.30"
	arrStopCore(11) = "192.168.210.31"
	arrStopCore(12) = "192.168.210.32"
	arrStopCore(13) = "192.168.210.33"
	arrStopCore(14) = "192.168.210.34"
	arrStopCore(15) = "192.168.210.35"
	arrStopCore(16) = "192.168.210.36"
	arrStopCore(17) = "192.168.210.37"
	arrStopCore(18) = "192.168.210.38"
	arrStopCore(19) = "192.168.210.39"
	arrStopCore(20) = "192.168.210.40"
	arrStopCore(21) = "192.168.210.41"
	arrStopCore(22) = "192.168.210.42"
	arrStopCore(23) = "192.168.210.43"
	arrStopCore(24) = "192.168.210.44"
	arrStopCore(25) = "192.168.210.45"
	arrStopCore(26) = "192.168.210.46"
	arrStopCore(27) = "192.168.210.47"
	arrStopCore(28) = "192.168.210.48"
	arrStopCore(29) = "192.168.210.49"
	arrStopCore(30) = "192.168.210.50"
	arrStopCore(31) = "192.168.210.51"
	arrStopCore(32) = "192.168.210.52"
	arrStopCore(33) = "192.168.210.53"
	arrStopCore(34) = "192.168.210.54"
	arrStopCore(35) = "192.168.210.55"
	arrStopCore(36) = "192.168.210.56"
	arrStopCore(37) = "192.168.210.57"
	arrStopCore(38) = "192.168.210.58"
	arrStopCore(39) = "192.168.210.59"
	arrStopCore(40) = "192.168.210.60"
	arrStopCore(41) = "192.168.210.61"
	arrStopCore(42) = "192.168.210.62"
	arrStopCore(43) = "192.168.210.63"
	arrStopCore(44) = "192.168.210.64"
	arrStopCore(45) = "192.168.210.65"
	arrStopCore(46) = "192.168.210.66"
	arrStopCore(47) = "192.168.210.67"
	arrStopCore(48) = "192.168.210.68"
	arrStopCore(49) = "192.168.210.69"
	arrStopCore(50) = "192.168.210.70"
	arrStopCore(51) = "192.168.210.71"
	arrStopCore(52) = "192.168.210.72"
	arrStopCore(53) = "192.168.210.73"
	arrStopCore(54) = "192.168.210.12"
	arrStopCore(55) = "192.168.210.13"
	arrStopCore(56) = "192.168.210.14"
	arrStopCore(57) = "192.168.210.15"
	arrStopCore(58) = "192.168.210.16"
	arrStopCore(59) = "192.168.210.17"
	arrStopCore(60) = "192.168.210.18"
	arrStopCore(61) = "192.168.210.19"
	arrStopCore(62) = "192.168.210.5"
	arrStopCore(63) = "192.168.210.6"
	arrStopCore(64) = "192.168.210.143"
	arrStopCore(65) = "192.168.210.144"
	arrStopCore(66) = "192.168.210.8"
	arrStopCore(67) = "192.168.210.9"
	arrStopCore(68) = "192.168.210.140"
	arrStopCore(69) = "192.168.210.141"
	arrStopCore(70) = "192.168.210.142"


Sub Main()

'Check if user is rtp99
	crt.Screen.Send "whoami" & vbCr
	If Not crt.Screen.WaitForString("rtp99", 2) Then
		MsgBox "You must be rtp99 user to execute this script!"
	Exit Sub
	End If

'Prompt for root password
	Dim passR
		passR = crt.Dialog.Prompt("Enter the ROOT password:", "Logon Script", "", True)
	If passR = ""  Then Exit Sub


'Identify VM type (cscf or icsf)
Dim vmType
	crt.Screen.Send "hostname | cut -c 6-9" & vbCr
		If crt.Screen.WaitForString("cscf", 2) Then
			vmType = "Core"
		Else
			vmType = "Standalone"
		End If

	
'Declare - status, stop or start rtp
	Dim doWhat
doWhat = crt.Dialog.Prompt("Enter 'status', 'stop' or 'start' :")
	If doWhat = ""  Then Exit Sub

Dim strDoCommand
		If doWhat = "start" Then 
			strDoCommand = "start rtp & disown"
		ElseIf doWhat = "stop" Then
			strDoCommand = "stop rtp & disown"
		Else
			strDoCommand = "status rtp | grep 'Active:' | grep -v 'active (exited)'"
		End If

Dim vHost
	If doWhat = "start" Then
		vHost = "arrStart" & vmType
	ElseIf doWhat = "start" Then
		vHost= "arrStop" & vmType
	Else
		vHost = "arrStart" & vmType
	End If
	MsgBox(strDoCommand) 'Correct as expected
	MsgBox(vHost)        'Correct as expected

For Each strHosts In vHost
    If strHosts = "" Then Exit For
	
    crt.Screen.Send"ssh -q " & strHosts & vbCr


Dim vWaitFors
vWaitFors = Array("(yes/no)?", _
					"bash-4", _
					"No route to host")

Do
	Dim nResult
	nResult = crt.Screen.WaitForStrings(vWaitFors, 1)

	Select Case nResult
		Case 0
'			MsgBox "Timed out waiting for strings!"
			crt.Sleep 100
			Exit Do

		Case 1
'		MsgBox "This is Case 1"
			crt.Screen.Send"yes" & vbCr
			crt.Screen.WaitForString"$"
			
		Case 2
'		MsgBox "This is Case 2"
			crt.Screen.WaitForString"$"
 
		Case 3
'		MsgBox "This is Case 2, No route to host."
		crt.Sleep 1000
			Exit Do


	End Select

	crt.Screen.Send"su - root" &vbCr
	crt.Sleep 5
	crt.Screen.WaitForString"assword"
	crt.Sleep 5
	crt.Screen.Send passR & vbCr
	crt.Screen.WaitForString">"
	crt.Screen.Send"echo;hostname;systemctl " & strDoCommand & vbCr
	crt.Screen.WaitForString">"
	crt.Screen.Send"exit" & vbCr
	crt.Screen.WaitForString"-bash-4.2$"
	crt.Screen.Send"exit" & vbCr
	crt.Screen.WaitForString"-bash-4.2$"
Loop
	crt.Sleep 1

Next
	MsgBox " *** End RTP script. *** "
	
End Sub

Any ideas?


Regards,
Bjoern
Reply With Quote
  #2  
Old 01-23-2019, 04:22 PM
ekoranyi ekoranyi is offline
VanDyke Technical Support
 
Join Date: Jan 2017
Posts: 654
Hi BjoernH,

Looking at line 307, it appears that vHost is a string, rather than an array.

If you add the below line of code right before line 307, what is the reported type of the vHost variable?
Code:
crt.Dialog.MessageBox(TypeName(vHost))
From what I see earlier in the code vHost is made up of either the string arrStart or arrStop and vmType. vmType itself is a string of either Core or Standalone. It appears that vHost is simply a concatenation of two strings not a reference to the actual array.

You may be able to resolve this issue using the Eval function.
Code:
For Each strHosts In Eval(vHost)
Does making this change give you the behavior you're looking for?
__________________
Thanks,
--Eric

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #3  
Old 01-24-2019, 09:58 AM
BjoernH BjoernH is offline
Registered User
 
Join Date: Mar 2018
Posts: 55
Thanks Eric! Working like a charm.

One more question, how would you insert a pause (sleep) between two vHosts in each array, eg:

Code:
Dim arrStartStandalone(49)
	arrStartStandalone(0) = "192.168.210.140"
	arrStartStandalone(1) = "192.168.210.141"
	arrStartStandalone(2) = "192.168.210.142"
Insert sleep here
	arrStartStandalone(3) = "192.168.210.5"
	arrStartStandalone(4) = "192.168.210.6"
Regards,
Bjoern
Reply With Quote
  #4  
Old 01-24-2019, 10:05 AM
ekoranyi ekoranyi is offline
VanDyke Technical Support
 
Join Date: Jan 2017
Posts: 654
BjoernH,

You won't be able to insert a sleep or pause in the array directly, this is something that would need to be done inside your For loop. This does limit the flexibility as the sleep would need to happen between every host or not at all.

Perhaps with a better understanding of the problem I can help suggest an alternative approach. What problem are you trying to solve with the sleep?
__________________
Thanks,
--Eric

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #5  
Old 01-24-2019, 10:13 AM
BjoernH BjoernH is offline
Registered User
 
Join Date: Mar 2018
Posts: 55
Quote:
Originally Posted by ekoranyi View Post
BjoernH,

You won't be able to insert a sleep or pause in the array directly, this is something that would need to be done inside your For loop. This does limit the flexibility as the sleep would need to happen between every host or not at all.

Perhaps with a better understanding of the problem I can help suggest an alternative approach. What problem are you trying to solve with the sleep?
When starting RTP on the servers, I need a 5 minute pause between certain types of servers. So for instance, after starting RTP on the first three servers .141, .142, 143, I need a pause so that they are fully enabled before starting RTP on the next two.

Bjoern
Reply With Quote
  #6  
Old 01-24-2019, 10:37 AM
ekoranyi ekoranyi is offline
VanDyke Technical Support
 
Join Date: Jan 2017
Posts: 654
BjoernH,

How many of the servers will require a sleep? Perhaps adding an If statement inside the For Each strHosts In vHost loop to check for these IP's and add a sleep would work.

The pseudo code below should help demonstrate this idea.

Code:
For Each strHosts In vHost
    If strHosts = "192.168.210.5"
        crt.Sleep <millisec>
    End If
__________________
Thanks,
--Eric

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -6. The time now is 07:52 PM.