View Single Post
  #9  
Old 08-27-2008, 08:23 AM
darkoth darkoth is offline
Registered User
 
Join Date: Jun 2007
Posts: 29
password script

Ok. it hung on the first part so I changed it to get it working through that. I also moved all the password prompts to the start of the script so it flows faster.

I thought I had it working but... it gets all the way to the end and then tried to ssh to #$, so I changed the script to replace #$ from the end of the server_list.txt file and of course now it tries to ssh to nothing... Any ideas on how to wrap this up? Is there something we can do to strip the last line of the file from the array and then replace?

New Script below:
Code:
#$language = "VBScript"
#$interface = "1.0"

Sub Main
	Dim szPrompt, objTab, szHost, vServerList

	szPrompt = "#$"
	Set objTab = crt.GetScriptTab
	objTab.Screen.Synchronous = True
	objTab.Screen.IgnoreEscape = True

	Do
		szPassword = crt.dialog.prompt("Please enter your password: ", "Password: ", "", True)
		If szPassword = "" then exit sub

		szRootPassword = crt.dialog.Prompt("Please enter the current ROOT password: ", "Root Password", "", True)
		If szRootPassword = "" then exit sub

		szNewPassword = crt.dialog.prompt("Please enter the new ROOT password: ", "New Password", "", True)
		If szNewPassword = "" then exit sub
                
		szConfirmPassword = crt.dialog.prompt("Please confirm the new ROOT password: ", "Confirm Password", "", True)
		If szConfirmPassword = "" then exit sub
                
		if szNewPassword <> szConfirmPassword then
			MsgBox "User did not provide matching passwords"
		Else
			Exit Do
		End if
	Loop

	szCommand = "cat server_list.txt"
        objTab.Screen.Send szCommand & vbcr

	objTab.Screen.WaitForString szCommand & vbcr
        vServerList = Split(objTab.Screen.ReadString(szPrompt), vbcr)

        For Each szHost in vServerList
		' Get rid of any carriage returns or line feeds that still may be
		' remaining in szHost
		szHost = Replace(szHost, "#$", "")
		szHost = Replace(Replace(szHost, vblf, ""), vbcr, "")
	    
		objTab.Screen.Send "ssh " & szHost & vbcr
		Do
			Dim szResult
			szResult = Crt.Screen.WaitforStrings("Are you sure you want to continue connecting (yes/no)? ", "Password:", 60)
			If szResult = 1 Then
				objTab.Screen.Send "yes" & vbcr
				objTab.Screen.WaitforString "Password: "
				objTab.Screen.Send szPassword & vbcr
				exit do
			End If
			If szResult = 2 Then
                       		objTab.Screen.Send szPassword & vbcr
                        	exit do
                	End If 
			If szResult = 0 Then
				MsgBox "We timed out"
				Exit sub
			End if
		Loop
		objTab.Screen.WaitforString "TERM = (xterm) " 
		objTab.Screen.Send "vt100" & vbcr
		objTab.Screen.WaitforString " ]# "
		objTab.Screen.Send "su -" & vbcr
		objTab.Screen.WaitForString "Password:"
		objTab.Screen.Send szRootPassword & vbcr
		objTab.Screen.WaitforString "TERM = (xterm) " 
		objTab.Screen.Send "vt100" & vbcr
		objTab.Screen.WaitforString " ]# "
		objTab.Screen.Send "passwd root" & vbcr
		ObjTab.Screen.WaitForString "New Password: "
		objTab.screen.Send szNewPassword & vbcr
		objTab.Screen.WaitForString "Re-enter new Password:"
		objTab.Screen.Send szNewPassword & vbcr
		objTab.Screen.WaitForString "passwd: password successfully changed for root"
		objTab.Screen.Send "exit" & vbcr
		objTab.screen.WaitForString "]#"
		objTab.Screen.Send "exit" & vbcr
		objTab.screen.WaitForString "]#"
	Next
	MsgBox "Script Completed."
End Sub

Last edited by darkoth; 08-27-2008 at 09:37 AM.
Reply With Quote