Welcome to the VanDyke Software Forums

Join the discussion today!


Go Back   VanDyke Software Forums > Scripting

Closed Thread
 
Thread Tools Rate Thread Display Modes
  #1  
Old 06-01-2015, 02:52 PM
abctx007 abctx007 is offline
Registered User
 
Join Date: Aug 2013
Posts: 8
Thumbs up sequential login to multiple hosts

Hi Eveyone, i am using vbscript from https://forums.vandyke.com/showthread.php?t=10651 but my requirement is very simple and i am not good at scripting so looking for help.

I want to login in to many hosts (probably 10) sequentially and i will execute commands separately, these are not stored sessions and my credentials are stored in global options. script posted in this forum is sending commands and quitting secureCRT which is not what i need and i dont know how to edit so somebody please help. all i need is just login to multiple hosts either via script or command line.
  #2  
Old 06-01-2015, 03:35 PM
jdev's Avatar
jdev jdev is offline
VanDyke Technical Support
 
Join Date: Nov 2003
Location: Albuquerque, NM
Posts: 920
Quote:
Originally Posted by abctx007 View Post
Hi Eveyone, i am using vbscript from https://forums.vandyke.com/showthread.php?t=10651 but my requirement is very simple and i am not good at scripting so looking for help.
That's OK if you're not good at scripting. Fortunately there's help available to you. We've created a good resource for learning about creating and running scripts within SecureCRT. Download the PDF (or view it inline within your browser) and take a look at chapter three, which will provide you with great information about connecting to hosts (even in tabs), and provide you with sample lines of code that you can use as you learn.

Quote:
Originally Posted by abctx007 View Post
I want to login in to many hosts (probably 10) sequentially and i will execute commands separately, these are not stored sessions and my credentials are stored in global options. script posted in this forum is sending commands and quitting secureCRT which is not what i need and i dont know how to edit so somebody please help. all i need is just login to multiple hosts either via script or command line.
Script examples are meant to be modified and customized to meet your needs - even if what you want to do may be very similar to the examples that are already available to you.

In your specific case, I think starting from scratch would be the easier way to go, since you don't need the complication of a hosts file separate from a commands file, as well as all the logging and other features of the example script your referenced.

Since your hosts are not stored as sessions, you'll be making ad hoc connections, and those are also explained in Chapter 3 of the Scripting Essentials: A Guide to Using VBScript in SecureCRT that I mentioned earlier.

Here's an example ad hoc SSH2 connection being made in VBScript code to a host with IP address of 192.168.0.1:

Code:
Set objNewTab = crt.Session.ConnectInTab("/SSH2 192.168.0.1", True, True)
Again, you can go to the scripting guide I've referenced to find more information and examples to build on.

Quote:
Originally Posted by abctx007 View Post
my credentials are stored in global options
This statement doesn't quite compute.

What, specifically, are you doing to have your credentials "stored in global options"?

--Jake
__________________
Jake Devenport
VanDyke Software
Technical Support
YouTube Channel: https://www.youtube.com/vandykesoftware
Email: support@vandyke.com
Web: https://www.vandyke.com/support
  #3  
Old 06-01-2015, 05:10 PM
abctx007 abctx007 is offline
Registered User
 
Join Date: Aug 2013
Posts: 8
Thumbs up

Thanks Jake for your reply, reason i store credentials in global options is for automate login. i have 30,000 hosts and i cannot save all sessions so when i want to connect any host i use ALT+R and enter hostname so that i am connected automatically.
  #4  
Old 06-01-2015, 05:17 PM
abctx007 abctx007 is offline
Registered User
 
Join Date: Aug 2013
Posts: 8
Thumbs up

Tks Jake that one line did work well but is there any way i can put all my hosts in single file rather than creating multiple lines in same script with different host.
  #5  
Old 06-01-2015, 05:29 PM
jdev's Avatar
jdev jdev is offline
VanDyke Technical Support
 
Join Date: Nov 2003
Location: Albuquerque, NM
Posts: 920
Quote:
Originally Posted by abctx007 View Post
Thanks Jake for your reply, reason i store credentials in global options is for automate login. i have 30,000 hosts and i cannot save all sessions so when i want to connect any host i use ALT+R and enter hostname so that i am connected automatically.
Ah... I see. So you have the Default session configured with a Logon Actions series or a saved username/password for use with your connections. Thanks for the clarification.

--Jake
__________________
Jake Devenport
VanDyke Software
Technical Support
YouTube Channel: https://www.youtube.com/vandykesoftware
Email: support@vandyke.com
Web: https://www.vandyke.com/support
  #6  
Old 06-01-2015, 05:41 PM
jdev's Avatar
jdev jdev is offline
VanDyke Technical Support
 
Join Date: Nov 2003
Location: Albuquerque, NM
Posts: 920
Quote:
Originally Posted by abctx007 View Post
...is there any way i can put all my hosts in single file rather than creating multiple lines in same script with different host.
Yes.

Read through section 7.2 of the scripting guide I referenced earlier. It shows how you can read data from a file. In that section, there's an example For Each...Next loop that shows how to iterate over the data that you've read from the file.

Using the information from section 7.2 of the scripting guide along with the example line of code that you already know how to work, you should be able to accomplish your goal in short order.

I encourage you to read through the scripting guide, as it will provide you with a number of tools that you can use to accomplish a wide variety of goals related to automation in SecureCRT.

You'll note, for instance that chapter 8 of the same scripting guide provides information about working with the windows clipboard, so the same principles could apply to operating on a list of hosts found in the clipboard, instead of read from a file.

--Jake
__________________
Jake Devenport
VanDyke Software
Technical Support
YouTube Channel: https://www.youtube.com/vandykesoftware
Email: support@vandyke.com
Web: https://www.vandyke.com/support
  #7  
Old 06-01-2015, 11:31 PM
abctx007 abctx007 is offline
Registered User
 
Join Date: Aug 2013
Posts: 8
Thumbs up

i did try to create script but i am facing difficulty in reading variable from file and throwing syntax error: i am missing something to call strLine

Sub Main
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objStream = objFSO.OpenTextFile("C:\Users\abctx007\Documents\MyDataFile.txt")
Do While objStream.AtEndOfStream <> True
strLine = objStream.ReadLine
Set objNewTab = crt.Session.ConnectInTab("/SSH2" &strLine, True, True)
crt.Session.Connect "/SSH2" & strLine &
Loop
objStream.Close

End Sub
  #8  
Old 06-05-2015, 06:00 PM
abctx007 abctx007 is offline
Registered User
 
Join Date: Aug 2013
Posts: 8
Thumbs up

one of my friend helped and finally it worked.
Sub Main
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objStream = objFSO.OpenTextFile("C:\Users\abctx007\Documents\CRThosts.txt")
strFileData = objStream.ReadAll
objStream.Close
vLines = Split(strFileData, vbcrlf)
For each strLine in vLines
Set objNewTab = crt.Session.ConnectInTab("/SSH2 " & strLine)
Next
objStream.Close
End Sub
Closed Thread


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