VanDyke Software Forums

VanDyke Software Forums (https://forums.vandyke.com/index.php)
-   Scripting (https://forums.vandyke.com/forumdisplay.php?f=14)
-   -   Need help with sending command to multiple tabs (https://forums.vandyke.com/showthread.php?t=2859)

darkoth 04-02-2008 09:00 AM

Need help with sending command to multiple tabs
 
I'm trying to create a script to send a command to multiple tabs.

In this instance, I'm trying to issue a sudo -s command

If "password:" is found return the password, if "#" is found then continue. I'm new at this and am trying to figure out where I'm going wrong. Thanks!

Code:

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

crt.Screen.Synchronous = True

Sub Main()

        For nIndex = 1 to crt.GetTabCount
                Set objCurrentTab = crt.GetTab(nIndex)
                objCurrentTab.Activate
                if objCurrentTab.Session.Connected = True then
                        crt.Sleep 500
                        objCurrentTab.Screen.Send "/usr/local/bin/sudo -s" & chr(13)

                        Dim result;
                        result = objCurrentTab.screen.WaitForString("Password:" , 5)

                        if result = "Password:"
                                objCurrentTab.Screen.Send "test123" & chr(13)
                        else continue;
                        crt.Sleep 1000
                end if
        Next

        ' turn off synchronous mode for normal input processing
        crt.Screen.Synchronous = False
End Sub


miked 04-02-2008 09:34 AM

I think that part of the problem may be that you're comparing result to a string. The result of WaitForString is True or False. Does the following code change work for you?
Code:

result = objCurrentTab.screen.WaitForString("Password:" , 5)

' result should be True or False, comment out this line: if result = "Password:"
If result = True Then


darkoth 04-02-2008 03:24 PM

Changed
 
I changed the script to this FYI to whoever wants it.. seems to work good now.

Code:

#$language = "VBScript"
#$interface = "1.0"
' Send sudo login information to all tabs

crt.Screen.Synchronous = True

Sub Main()

        Dim result

        For nIndex = 1 to crt.GetTabCount
                Set objCurrentTab = crt.GetTab(nIndex)
                objCurrentTab.Activate
                if objCurrentTab.Session.Connected = True then
                        crt.Sleep 500
                        objCurrentTab.Screen.Send "/usr/local/bin/sudo -s" & chr(13)

                        result = objCurrentTab.screen.WaitForString("Password:", 2)

                        ' result should be True or False
                        If result = True Then
                                objCurrentTab.Screen.Send "test123" & chr(13)
                        end if

                        crt.Sleep 1000
                end if
        Next
End Sub



All times are GMT -6. The time now is 02:16 AM.