Welcome to the VanDyke Software Forums

Join the discussion today!


Go Back   VanDyke Software Forums > Scripting

Notices

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 04-02-2008, 08:00 AM
darkoth darkoth is offline
Registered User
 
Join Date: Jun 2007
Posts: 29
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
Reply With Quote
  #2  
Old 04-02-2008, 08:34 AM
miked's Avatar
miked miked is offline
Registered User
 
Join Date: Feb 2004
Posts: 2,039
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]
Reply With Quote
  #3  
Old 04-02-2008, 02:24 PM
darkoth darkoth is offline
Registered User
 
Join Date: Jun 2007
Posts: 29
Talking 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
Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -6. The time now is 02:15 PM.