View Single Post
  #4  
Old 08-25-2008, 11:21 AM
jjh jjh is offline
VanDyke Customer Support
 
Join Date: Feb 2004
Posts: 815
I've made some changes to the script, which you can see in
the attached screenshot. As you can see, the following
changes were made:

We had originally defined "szRezults", but we were using
"szResult", so I changed "szResults" to "szResult" to match.

Next, I made a change to wait for the prompt before starting
the password change

The next changes I made were to exit the sub if the user
cancels the "New Password" or "Confirm Password" prompts.

The next change fixes a problem with the Do, Loop. I think
this is the actual problem you experienced.

Lastly, I made a change to wait for the prompt before
starting the process over again.

Here is the new version of the script:

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

crt.Screen.Synchronous = True

Sub Main
        crt.Screen.Send "cat server_list.txt" & vbcr
        vServerList = Split(crt.Screen.ReadString("]$"), vbcr)

        For Each szHost in vServerList
            crt.Screen.Send "ssh " & szHost & vbcr
            Do
                szResult = Crt.Screen.WaitforStrings("Are you sure...", "Password:", 60) = 1
                Select Case szResult
                        Case 1
                            crt.Screen.Send "yes" & vbcr
                        Case 2
                            szPassword = crt.dialog.prompt("Please enter your password", "Password", "", True)
                            crt.Screen.Send szPassword & vbcr
                            exit do
                        Case else
                            MsgBox "We timed out"
                            Exit sub
                end select
            Loop

            crt.Screen.Send "su -" & vbcr
            crt.Screen.WaitForString "Password:"
            szRootPassword = crt.dialog.Prompt("Please enter the root password: ", "Root Password", "", True)
            crt.Screen.Send szRootPassword & vbcr
            szResult = crt.screen.waitforstring ("]$", 10)
            If szResult = 0 then
                msgbox "Did not find root shell prompt."
                Exit sub
            End if
            crt.Screen.Send "passwd root" & vbcr
            Do
                szNewPassword = crt.dialog.prompt("Please enter the new password: ", "New Password", "", True)
                If szNewPassword = "" then exit sub
                
                szConfirmPassword = crt.dialog.prompt("Please confirm your new 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

                crt.screen.Send szNewPassword & vbcr
                crt.Screen.WaitForString "Re-enter new Password:"
                crt.Screen.Send szNewPassword & vbcr
                crt.Screen.WaitForString "passwd: password successfully changed for root"
                crt.Screen.Send "exit" & vbcr
                crt.screen.WaitForString "]$"
        Next
End Sub
Does this work better for you now?

JJH
Attached Images
File Type: gif ScriptDifferences.gif (33.7 KB, 762 views)
Reply With Quote