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 10-09-2018, 02:52 AM
shea_nb shea_nb is offline
Registered User
 
Join Date: Oct 2018
Posts: 2
Scripting Multiple Sessions Through a Jumpbox

I am very new to scripting in SecureCRT and am currently editing a .bat file for connecting to multiple devices at once. It requires a plain text login and password which I desperately need to get away from. This is currently the format of the .bat file which the hostnames are edited a few times a night to connect to the specific devices. This will open each device in a seperate tab and allow me to run various other .vbs files or just type out commands.


cd \Program Files\VanDyke Software\Clients

SecureCRT /T /SSH2 /ACCEPTHOSTKEYS /PASSWORD XXXXXXXX /L user hostname1
SecureCRT /T /SSH2 /ACCEPTHOSTKEYS /PASSWORD XXXXXXXX /L user hostname2
SecureCRT /T /SSH2 /ACCEPTHOSTKEYS /PASSWORD XXXXXXXX /L user hostname3
SecureCRT /T /SSH2 /ACCEPTHOSTKEYS /PASSWORD XXXXXXXX /L user hostname4
SecureCRT /T /SSH2 /ACCEPTHOSTKEYS /PASSWORD XXXXXXXX /L user hostname5
SecureCRT /T /SSH2 /ACCEPTHOSTKEYS /PASSWORD XXXXXXXX /L user hostname6
SecureCRT /T /SSH2 /ACCEPTHOSTKEYS /PASSWORD XXXXXXXX /L user hostname7
SecureCRT /T /SSH2 /ACCEPTHOSTKEYS /PASSWORD XXXXXXXX /L user hostname8
SecureCRT /T /SSH2 /ACCEPTHOSTKEYS /PASSWORD XXXXXXXX /L user hostname9
SecureCRT /T /SSH2 /ACCEPTHOSTKEYS /PASSWORD XXXXXXXX /L user hostname0


We have a jumpbox with a built in script for connecting to devices in the same manner and I am trying to figure out how to build a more efficient .bat or .vbs to perform this task.


cd \Program Files\VanDyke Software\Clients


SecureCRT /T /S "my_jumpbox"


Would be the example for connecting to the jumpbox. It also has a built in script for connecting to devices and because it uses an SSH Key no login or pass is needed in a plain text file. Below is the example output needed to connect to devices.

my_jumpbox$ ym hostname1

That will allow me to connect to the device from the jumpbox without the need to enter a login/pass. I am just hitting a wall on trying to get this scripted into a .bat or .vbs file or both so that I can get away from the aforementioned process of saving a pass in a plain text file. Whether anyone can just point me in the right direction or provide an example output for opening the jumpbox via multiple tabs at once with send strings would help. The goal is having only one file that would have to be edited with the hostnames which I could accomplish with replace strings or another formula.
Reply With Quote
  #2  
Old 10-09-2018, 10:22 AM
ekoranyi ekoranyi is offline
VanDyke Technical Support
 
Join Date: Jan 2017
Posts: 654
Hi shea_nb,

It sounds like an interesting problem you're trying to solve. I cam imagine several ways to tackle this one. Can you tell me a little more about your use case? It looks like you're using ad-hoc connections rather than saving a session for each host you're connecting to, is there a reason you're not saving sessions? Is there a reason you're launching from the command line rather than from inside SecureCRT?

It does appear that you have a session saved for your jump box named my_jumpbox. One option would be to configure this session to use a logon script. The script would read in a hostname argument and use it to build the appropriate command to send to the jump box. This script might look something like:

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

If crt.Arguments.Count > 0 Then
    strHostname = crt.Arguments(0)
Else
    crt.Dialog.MessageBox "No Hostname Provided"
End If

'Wait for the prompt to appear
crt.Screen.WaitforString "my_jumpbox$"
'Send the command to connect to host
crt.Screen.Send("ym " & strHostname & vbcr)
This would be configured by right clicking on the my_jumpbox session and choosing Properties. In the Session Options window select the Logon Actions category. Enable the Logon Script option and provide the path to the script file.

This would allow you to launch SecureCRT from the command line using:

Code:
SecureCRT.exe /T /Arg hostname1 /S my_jumpbox
This would connect to the jumb box sessions, the logon script would read the argument and send the appropriate "ym hostname1" command. To make this process even easier I might consider creating a batch file that handles most of it for me.

Code:
set HostARG=%1
"c:\Program Files\VanDyke Software\Clients\SecureCRT.exe" /T /ARG %HostARG% /s my_jumpbox
I would name this batch file something like connect.bat and save it in a location that is in the Windows path. This would make it very easy to connect to your sessions, simply type "connect hostname1" at your prompt. You wouldn't even need to modify your batch files nightly.

Does this help get you the behavior you're looking for?
__________________
Thanks,
--Eric

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #3  
Old 10-10-2018, 03:40 AM
shea_nb shea_nb is offline
Registered User
 
Join Date: Oct 2018
Posts: 2
Yes that does help, ty.
Reply With Quote
Reply

Tags
jumpbox jump box , multiple at once , scripting

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 04:38 AM.