Welcome to the VanDyke Software Forums

Join the discussion today!


Go Back   VanDyke Software Forums > Scripting

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 08-02-2015, 09:36 AM
sosogh@126.com sosogh@126.com is offline
Registered User
 
Join Date: Aug 2015
Posts: 4
How to open multiple sessions in tabs (using script) in the exsited SecureCRT instanc

Hi
I want to open multiple sessions in tabs (using script) in the "exsited" SecureCRT instance,
something like this post https://forums.vandyke.com/showthread.php?t=8970.
I have followed the tips : single mode https://forums.vandyke.com/showpost.php?p=33232.
But it seems that it doesn't work. (the multiple sessions will be still opened in a new SecureCRT instance ).
Is there anything I miss ?

========================
my code is :
#$language = "VBScript"
#$interface = "1.0"

Sub Main
' Connect to three separate sessions each in its own tab.
Dim objTab1, objTab2, objTab3
Set objTab1 = crt.Session.ConnectInTab("/SSH2 /L root /P 22 /PASSWORD 123123 192.168.1.1")
objTab1.Caption = "test1"
Set objTab2 = crt.Session.ConnectInTab("/SSH2 /L root /P 22 /PASSWORD 123123 192.168.1.2")
objTab2.Caption = "test12"
Set objTab3 = crt.Session.ConnectInTab("/SSH2 /L root /P 22 /PASSWORD 123123 192.168.1.3")
objTab3.Caption = "test13"
End Sub

========================
How I run the script is :
G:\Program Files\VanDyke Software\Clients>SecureCRT.exe /script test.vbs

========================
my OS is win7 64bit ,SecureCRT is Version 7.2.5 (x64 build 550) - Official Release

Thx

Last edited by jdev; 11-09-2017 at 11:33 AM.
Reply With Quote
  #2  
Old 08-03-2015, 08:12 AM
rtb rtb is offline
VanDyke Technical Support
 
Join Date: Aug 2008
Posts: 4,306
Hi,

Thanks for the post.

What version of SecureCRT are you using?

Are you able to accomplish your goal if you add "/T" to your command line?

For example:
SecureCRT.exe /T /Script test.vbs
__________________
--Todd

VanDyke Software
Technical Support
support@vandyke.com
505-332-5730
Reply With Quote
  #3  
Old 08-03-2015, 07:36 PM
sosogh@126.com sosogh@126.com is offline
Registered User
 
Join Date: Aug 2015
Posts: 4
my OS is win7 64bit ,SecureCRT is Version 7.2.5 (x64 build 550) - Official Release

>>Are you able to accomplish your goal if you add "/T" to your command line?

it show error:
when the "/T" option is used on the cmomand line ,a Hostname or IP address must be specified
Reply With Quote
  #4  
Old 08-04-2015, 04:23 PM
rtb rtb is offline
VanDyke Technical Support
 
Join Date: Aug 2008
Posts: 4,306
Hi,

There are a couple of ways you might accomplish your goal, but I would like to know what problem you are trying to solve.

Can you tell me more about why you need to launch with a script and have the sessions appear in an existing instance?

You can do the same thing using the Quick Connect dialog or run the script from within the existing SecureCRT instance using the Script menu. You could even configure a button on the Button Bar to run your script.

How do these options not meet your needs?
__________________
--Todd

VanDyke Software
Technical Support
support@vandyke.com
505-332-5730
Reply With Quote
  #5  
Old 08-05-2015, 12:38 AM
sosogh@126.com sosogh@126.com is offline
Registered User
 
Join Date: Aug 2015
Posts: 4
thx

>> run the script from within the existing SecureCRT instance using the Script menu. You could even configure a button on the Button Bar to run your script.

I have test these two method , they works.
In fact ,the final way which I want to open the ssh sesson is
place the servers list in notepad++ ---> call nppexec ----> call securecrt ---> call script to open the ssh session


why I need to launch with a script and have the sessions appear in an existing instance is :
I have to ssh to some servers often(not at the same time ) , if the sessions appear in an existing instance,
I will close only one instance to close all sessions , otherwise , I have to close many instances to close the sessions
Reply With Quote
  #6  
Old 08-05-2015, 04:30 PM
rtb rtb is offline
VanDyke Technical Support
 
Join Date: Aug 2008
Posts: 4,306
Hi,

I have created a feature request to make it possible to use the /T command-line option with /Script, but not use a hostname. We will post to this thread if we add this feature in a future SecureCRT release.

If you would like to be notified directly, please complete and submit the form at the following location:
Submit Feature Request
In the meantime, would you be able to run a script within SecureCRT to connect your sessions?

If not, can you tell me more about what problem is solved by using nppexec to connect the sessions?
__________________
--Todd

VanDyke Software
Technical Support
support@vandyke.com
505-332-5730
Reply With Quote
  #7  
Old 08-09-2015, 07:34 PM
sosogh@126.com sosogh@126.com is offline
Registered User
 
Join Date: Aug 2015
Posts: 4
>>can you tell me more about what problem is solved by using nppexec to connect the sessions?

The main goal is to batch open session .
It is convince to select list of vms in notepad++ and then press a customer defined shortcut , such as alt+s , then nppexec will call securecrt(script)
to batch open them.

so far , I have known about it with securecrt.
Thx
Reply With Quote
  #8  
Old 08-10-2015, 02:58 PM
rtb rtb is offline
VanDyke Technical Support
 
Join Date: Aug 2008
Posts: 4,306
Hi,

Thanks for the information about your goal. We will post to this forum thread if we add the ability to accomplish your goal.

In the meantime, you could create a session that connects to a server, and you don't care if it gets connected. You could the use that session to run your script. For example, if you named your session "bogus", you could use the following:
SecureCRT.exe /script test.vbs /T /S bogus
__________________
--Todd

VanDyke Software
Technical Support
support@vandyke.com
505-332-5730
Reply With Quote
  #9  
Old 10-25-2017, 09:17 AM
tcurtis45 tcurtis45 is offline
Registered User
 
Join Date: Jan 2016
Posts: 15
Any update on this feature

I too would like to launch a tab using /script but have figure out a workaround since it doesn't appear this is natively possible.

No activity in two years. Any update on this feature? I assume not since I am still being prompted to specify a session.

Thanks
Reply With Quote
  #10  
Old 10-25-2017, 09:52 AM
ekoranyi ekoranyi is offline
VanDyke Technical Support
 
Join Date: Jan 2017
Posts: 654
Hi tcurtis45,

This feature request that was discussed in this thread has not yet been implemented.

I've added your contact information to the feature request and we'll be sure to let you know if a version of SecureCRT becomes available with this functionality.

In the meantime can you tell me a little more about the problem you are trying to solve and your use case? With a little more information I may be able to suggest a work around to get the behavior you're looking for.
__________________
Thanks,
--Eric

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #11  
Old 10-26-2017, 11:52 AM
tcurtis45 tcurtis45 is offline
Registered User
 
Join Date: Jan 2016
Posts: 15
Batch job

It may just be how I am presenting on the command line, but I can't figure out the syntax. I am trying to launch a batch process so that I can connect to multiple instances at the same time via command line. For instance, this is what I want to do where connect.vbs has the data in the script to force a connection to a terminal.

The following works for me in individual windows:

securecrt /script "connect.vbs" /arg -t:CiscoTermSrv /arg -p:2011 /arg -u:username /arg -p:password /arg -i:install_switch1.vbs /arg -h:10.10.10.1

securecrt /script "connect.vbs" /arg -t:CiscoTermSrv /arg -p:2012 /arg -u:username /arg -p:password /arg -i:install_switch2.vbs /arg -h:10.10.10.1

securecrt /script "connect.vbs" /arg -t:CiscoTermSrv /arg -p:2013 /arg -u:username /arg -p:password /arg -i:install_switch3.vbs /arg -h:10.10.10.1

My script parses all of the arguments, including hostname, and then passes them through a connect script (taken from the sample ExcelSpreadsheets-ReadingAndWriting function called Connect). Obviously the problem is it launches in 20 windows if i send 20 iterations of the batch.

If i try and launch using the /t option I get a few different response.

Using the option below, I get a connection in a tab, but it throws the error: Invalid command line option /script. Obviously script does not run, so nothing happens other than connection int he windows.

securecrt /t 10.10.10.1 /script "connect.vbs" /arg -t:CiscoTermSrv /arg -p:2013 /arg -u:username /arg -p:password /arg -i:install_switch3.vbs3

If I re-arrange the order to the following I get the error: The specified address is not available from the local computer. It does open in individual tabs, but nothing is connecting, and my script (which works standalone) is not being executed.

securecrt /script "connect.vbs" /arg -t:CiscoTermSrv /arg -p:2013 /arg -u:username /arg -p:password /arg -i:install_switch3.vbs3 /t 10.10.10.1

Thanks for the assistance!

Tony

Last edited by jdev; 10-26-2017 at 12:06 PM. Reason: Disable smilies
Reply With Quote
  #12  
Old 10-26-2017, 02:21 PM
ekoranyi ekoranyi is offline
VanDyke Technical Support
 
Join Date: Jan 2017
Posts: 654
Hi tcurtis45,

It seems like one option would be to connect directly to the devices in your first set of commands instead of using the connect script. Is there a reason that you can't do something like below?

Code:
SecureCRT /SCRIPT install_switch1.vbs /T /SSH2 /PASSWORD <password>  <username>@10.10.10.1:2011

SecureCRT /SCRIPT install_switch2.vbs /T /SSH2 /PASSWORD <password>  <username>@10.10.10.1:2011

SecureCRT /SCRIPT install_switch3.vbs /T /SSH2 /PASSWORD <password>  <username>@10.10.10.1:2011
I'm not clear on what the "/arg -t:CiscoTermSrv" is used for but you may also be able to build that into the initial command as well.

It seems like, barring any hurdles, you should be able to wrap something similar to above in a .bat and get the behavior you're looking for.
__________________
Thanks,
--Eric

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #13  
Old 10-27-2017, 09:08 AM
tcurtis45 tcurtis45 is offline
Registered User
 
Join Date: Jan 2016
Posts: 15
Worked fine

I redid the code and yes, it works fine. I will have to update a few things to make it work.

FYI the flags for MRV and port numbers are referring to post-connection settings that should have been executed after the device was connected. I was just relying on the script to do everything, rather than allowing the command line to handle the connection piece.

Thanks for your help.
Reply With Quote
  #14  
Old 10-27-2017, 09:20 AM
ekoranyi ekoranyi is offline
VanDyke Technical Support
 
Join Date: Jan 2017
Posts: 654
Hi tcurtis45,

I'm glad to hear you were able to get it working in the way that you want.

I hope my assumptions about how the args were being used didn't cause too much of a headache.

Have a great weekend.
__________________
Thanks,
--Eric

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #15  
Old 10-27-2017, 04:45 PM
tcurtis45 tcurtis45 is offline
Registered User
 
Join Date: Jan 2016
Posts: 15
Send args to correct tab

Erik,

When launced individually, i was not havving problems, but now my arguments are not properly making it to the tab from which the script was launched. I tried the following code but have not have any luck (sConfigFile is passed as an argument at command line.)

Code:
#$Language="VBScript"
#$Interface="1.0"

Dim sConfigFile, g_objTab

Set g_objTab = crt.GetScriptTab()

Get_Arguments

g_objTab.Caption = sConfigFile
g_objTab.Screen.Synchronous = True



Sub Get_Arguments()
 	 
	If crt.Arguments.Count > 0 Then
		' Split the variable into an array using semicolon as delimeter
		Dim sArgs
		sArgs = crt.Arguments.Count
		'msgBox "sArgs = " & sArgs
		Dim oArg()
		sArgs = sArgs - 1
		ReDim oArg (sArgs)
		'msgBox " sArgs is set to : " & sArgs & vbcrlf & crt.Arguments (sArgs)
		Do While sArgs => 0
			oArg (sArgs) = crt.Arguments(sArgs)
		'	msgBox "Argument is: " & oArg (sArgs) & vbcrlf & _
		'			" sArgs is set to : " & sArgs
			sArgs = sArgs - 1
			if sArgs = -1 then Exit Do
		Loop
	
	 For Each i in oArg
		  sSwitch = LCase(Left(i,3))
		  sValue = Right(i,Len(i)-3)
			
			Select Case sSwitch
				Case "-i:"
					sInput = sValue
				Case "-c:"
					sConfigFile = sValue
				Case "-t:"
					sConnectionType = sValue
				Case "-a:"
					sPortNumber = sValue
			End Select
		Next


'	 crt.dialog.MessageBox "Config File: " & sConfigFile
	 
	End If 
	 
 End Sub
In this example, each window renamed itself to the last tab launched, and they also each pass the same port # variable even though they all have different numbers assigned.

So if I executed this from command line:
Code:
SecureCRT.exe /script renametabs.vbs /arg -c:router1.txt /T /SSH2 /PASSWORD pass123 username@10.1.1.1
SecureCRT.exe /script renametabs.vbs /arg -c:switch1.txt /T /SSH2 /PASSWORD pass123 username@10.1.1.1
SecureCRT.exe /script renametabs.vbs /arg -c:switch2.txt /T /SSH2 /PASSWORD pass123 username@10.1.1.1
In this scenario, they all connect, but they all get renamed to switch2.txt since it was the last thing passed. I tried using the tab object to get arguments, but that didn't work.

I'm sure i'm overlooking something simple. Thanks for the help.

Tony

Last edited by tcurtis45; 10-28-2017 at 05:00 AM.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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 09:33 PM.