#1
|
|||
|
|||
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 |
#2
|
||||
|
||||
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
__________________
Mike VanDyke Software Technical Support [http://www.vandyke.com/support] |
#3
|
|||
|
|||
![]()
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 |
![]() |
Thread Tools | |
Display Modes | Rate This Thread |
|
|