Welcome to the VanDyke Software Forums

Join the discussion today!


Go Back   VanDyke Software Forums > Scripting

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 03-06-2019, 03:38 PM
BjoernH BjoernH is offline
Registered User
 
Join Date: Mar 2018
Posts: 40
Need help with Case/Do/Loop (again)

Good day.

I always seem to run into the same problem but every time it seems to be different.

My script is supposed to loop through an array of IP addresses, check for the existence of a file and return an answer depending on whether the file exists or not.

It does ssh to the first host, confirms the file exists 'User gstool already exists' line 218 of the code, then proceeds to exit up to line 227. But instead of looping back and pick up the next IP address, it goes back to line 206 (su - root) and does the same check for the file on the same host again, does the same exit in lines (222 -227), but this time loses connection to the host and the script ends prematurely.

My script:
Code:
'#$language = "VBScript"
'#$interface = "1.0"
' File: vCSCF-SA&Core-CMDALL.vbs
' Create date:	12/21/2018
' Modified:		01/24/2019


crt.Screen.Synchronous = True

Sub Main()

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

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

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

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

Dim pwGST
pwGST = crt.Dialog.Prompt("Enter the new gstool password:", "Logon Script", "", True)
	If pwGST = ""  Then Exit Sub

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

	
Dim vHost
	If vmType = "arrStandalone" Then
		vHost = arrStandalone
	Else vHost = arrCore
	End If
	
'ssh to hosts
For Each strHosts In vHost
    If strHosts = "" Then Exit For

    crt.Screen.Send"echo;echo;echo Logging into " & strHosts & vbCr
	crt.Screen.WaitForString "$ "
    crt.Screen.Send"ssh " & strHosts & vbCr
	crt.Sleep 1000


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

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

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

		Case 1
			crt.Screen.Send"yes" & vbCr
			crt.Screen.WaitForString"$"

		Case 2
			crt.Screen.WaitForString"$"

		Case 3
		crt.Sleep 1000
			Exit Do


	End Select
	
'Do something...	
	crt.Screen.Send"su - root" &vbCr
	crt.Sleep 100
	crt.Screen.WaitForString"assword"
	crt.Sleep 100
	crt.Screen.Send passR & vbCr
	crt.Screen.WaitForString">"
	crt.Screen.Send"ls /opt/SMAW/SMAWrbac/conf/GS_USER.cfg" & vbCr
	
	If crt.Screen.WaitForString("No such file or directory", 3) Then
		crt.Screen.Send"echo CREATE THE DIRECTORY" & vbCr
		crt.Screen.WaitForString">"
	Else
		crt.Screen.Send "echo;echo 'User gstool already exists';echo" & vbCr
		crt.Screen.WaitForString "> "
		
	End If
		crt.Screen.Send"exit" & vbCr
		crt.Screen.WaitForString"$"
		crt.Screen.Send"uname -n" &vbCr
		crt.Sleep 100
		crt.Screen.Send"exit" & vbCr
		crt.Screen.WaitForString"closed."
	
Loop
	crt.Sleep 1
	

Next
	MsgBox "End GS User Add."

End Sub

I can supply the script and log file if you need them.

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

I'm sorry to hear you're having trouble. Unfortunately I don't know that we have sufficient information to start troubleshooting the issue.

We will almost always require:
  1. A description of the issue
  2. The full script code (Please attach as .txt file)
  3. A log file demonstrating the output of running the script (Please attach as .txt file)
  4. The version of SecureCRT being used

Going forward, to help reduce the overhead, it may be best if you reach out directly via email to Support@VanDyke.com and include this information in the first message.
__________________
Thanks,
--Eric

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #3  
Old 03-06-2019, 08:16 PM
BjoernH BjoernH is offline
Registered User
 
Join Date: Mar 2018
Posts: 40
Hi Eric.

Please find attached the script and log as requested.



Regards,
Bjoern
Attached Files
File Type: txt gstoolUserAdd-ISM.log.txt (3.0 KB, 7 views)
File Type: txt vCSCF-gstool-userAdd.vbs.txt (6.5 KB, 9 views)
Reply With Quote
  #4  
Old 03-07-2019, 08:55 AM
ekoranyi ekoranyi is offline
VanDyke Technical Support
 
Join Date: Jan 2017
Posts: 654
Hi BjoernH,

Please send an email to Support@VanDyke.com with "Attn: Eric Forum Post 13433" in the subject line. Please be sure to attach the script, log file, and include the version of SecureCRT you are currently running.
__________________
Thanks,
--Eric

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


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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 08:42 PM.