VanDyke Software Forums

VanDyke Software Forums (https://forums.vandyke.com/index.php)
-   Scripting (https://forums.vandyke.com/forumdisplay.php?f=14)
-   -   WaitForStrings with the possibility of different prompts returned (https://forums.vandyke.com/showthread.php?t=13471)

Reno 03-27-2019 10:48 AM

WaitForStrings with the possibility of different prompts returned
 
In a VBscript, I'm issuing an SSH command. When that SSH is performed, there are two possibilities:
1) the prompt will change to "[admin@xyz123 ~]$ "
2) the VM will ask for the admin passowrd to complete the SSH, where the prompt will look like:
admin@1.1.1.1's password:

I was trying to figure out how to do a "crt.Screen.WaitForString" where the script waits for either prompt and then takes action based on which prompt is returned.

I'm having a little difficulty getting an example working. From looking at the docs, I was thinking it should look something like:
result = crt.screen.WaitForStrings("admin@1.1.1.1's password: ", "[admin@xyz123 ~]$ ", 10)
If result = 1 Then crt.screen.send "testl"
If result = 2 Then crt.screen.send "test2"
If result = 0 Then
MsgBox "Error: Timed out waiting for prompt!"
End If

Thanks for any help!

bgagnon 03-27-2019 11:11 AM

Hi Reno,

Your code looks fine to me (and worked for me in a quick test). I did add a synchronous statement (and used crt.Dialog.MessageBox for all cases rather than send something to the remote):
Code:

crt.Screen.Synchronous = True
crt.Screen.Send "ssh 192.1.1.1" & vbcr
result = crt.screen.WaitForStrings("assword: ", "~]$ ", 10)
If result = 1 Then crt.Dialog.MessageBox "Received password prompt"
If result = 2 Then crt.Dialog.MessageBox "Already logged in as user"
If result = 0 Then crt.Dialog.Messagebox "Error: Timed out waiting for prompt!"

What were your results?

Reno 03-27-2019 01:20 PM

I got it working. I pasted in your code and then changed out the values with mine. That's all I did. Maybe there was something just a little off in the example I pasted.

One things I know, is when I get this things figured out, I'll forever have working examples to copy off myself instead of having to ask questions.

I really appreciate the help. Thank you sir!

bgagnon 03-27-2019 01:56 PM

Hi Reno,

I'm glad you got it working.

Quote:

Thank you sir!
Wrong gender, but that's OK. :)

Reno 03-27-2019 03:44 PM

Opps. Pardon. Thank you Ma'am! :)


All times are GMT -6. The time now is 12:39 AM.