Welcome to the VanDyke Software Forums

Join the discussion today!


Go Back   VanDyke Software Forums > Scripting

Reply
 
Thread Tools Rate Thread Display Modes
  #106  
Old 11-23-2016, 08:58 AM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,313
Hi netsecrets00,

As I posted in the other thread, there is a different example available for a jump host scenario. The example script being discussed here does assume you will be making only one connection and that is from SecureCRT, not a jump host.
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #107  
Old 04-12-2017, 04:57 AM
Tekjunkie Tekjunkie is offline
Registered User
 
Join Date: Sep 2010
Posts: 20
Would it be possible, or how would I go about adding a dynamic dir level in the logtemplate name based on the HOSTNAME (session name).


I have tried to add it various ways but keep having issues after the "g_fso.OpenTextFile" it seems to work the first time around then errors out.


Quote:
original:
g_strLogFileTemplate = _
g_strMyDocs & "\##IPADDRESS--COMMAND--YYYY-MM-DD--hh'mm'ss.txt"
Quote:
desired
g_strLogFileTemplate = g_strMyDocs & "\CommandsFolder\Logs\" & [SESSION_NAME] & "\##HOST-temp.txt" '--YYYY-MM-DD--hh'mm'ss.txt"

I have attached the hacked up file I am working on, please pardon the mess I am learning.
Attached Files
File Type: txt multi command individual logging.txt (18.5 KB, 400 views)
Reply With Quote
  #108  
Old 04-12-2017, 09:12 AM
ekoranyi ekoranyi is offline
VanDyke Technical Support
 
Join Date: Jan 2017
Posts: 654
Hi Tekjunkie,

Does your msgbox for jHost2 display the expected hostname?

Can you elaborate on what you mean by it seems to work the first time?

What error are you seeing?

There may be an easier way to get at the hostname. I've included a snippet below that will allow you to access the hostname by grabbing it from the sessions .ini file.

Code:
Set objConfig = crt.Session.Config
jHost2 = objConfig.GetOption("Hostname")
__________________
Thanks,
--Eric

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #109  
Old 04-12-2017, 01:30 PM
Tekjunkie Tekjunkie is offline
Registered User
 
Join Date: Sep 2010
Posts: 20
Thank you for the simplification on getting the hostname. Question, is there a similar method to get the session or Tab name?


Now on to the issue --

This is the setup



Code:
Dim Hostname, objFolder
				
Set objConfig = crt.Session.Config
Hostname = objConfig.GetOption("Hostname")
msgbox "Hostname " & Hostname


g_strLogFileTemplate = g_strMyDocs & "\CommandsFolder\Logs\" & Hostname & "\temp--YYYY-MM-DD--hh'mm'ss.txt"

which makes it all the way down to the replacing of the time stamp placeholders.

Code:
C:\User\xxxx\Desktop\CommandFolder\172.21.131.134\BANG--2017-04-12--14'19'04.txt
The issue appears to be that I am not creating the needed folder from "HOSTNAME"

I tried this but no joy. I everything here exists except the HOSTNAME. I just need the HOSTNAME created under the existing Logs folder if it does not exist


Code:
	
Set g_folder = CreateObject("Scripting.FileSystemObject")
set objFolder = g_strMyDocs & "\CommandsFolder\Logs\" & Hostname & "\"
	
if not g_folder.FolderExists(objFolder) then
	g_folder.CreateFolder objFolder
End if
Reply With Quote
  #110  
Old 04-12-2017, 02:09 PM
Tekjunkie Tekjunkie is offline
Registered User
 
Join Date: Sep 2010
Posts: 20
fixed it. took out the "SET" and all is good
Code:
original:
set objFolder = g_strMyDocs & "\CommandsFolder\Logs\" & Hostname & "\"

working:
objFolder = g_strMyDocs & "\CommandsFolder\Logs\" & Hostname & "\"
Reply With Quote
  #111  
Old 04-12-2017, 02:48 PM
ekoranyi ekoranyi is offline
VanDyke Technical Support
 
Join Date: Jan 2017
Posts: 654
Hi Tekjunkie,

I'm glad to hear that you got it working.

To answer your question about getting the tab name, yes. I've included an example of how to get at the session/tab name.


To get the Session Name:

Code:
strSessionName = crt.Session.Path
If the Session is in a folder you could use:

Code:
strSession = crt.Session.Path
If Instr(strSession, "\") Then
    vSession = Split(strSession, "\")
    strSession = vSession(1)
    MsgBox strSession
Else
    MsgBox strSession
End If
__________________
Thanks,
--Eric

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #112  
Old 04-12-2017, 03:25 PM
Tekjunkie Tekjunkie is offline
Registered User
 
Join Date: Sep 2010
Posts: 20
Option number 2 worked perfectly !!

Thank you for the assist!
Reply With Quote
  #113  
Old 04-12-2017, 03:30 PM
ekoranyi ekoranyi is offline
VanDyke Technical Support
 
Join Date: Jan 2017
Posts: 654
Hi Tekjunkie,

I'm glad I could help point you in the right direction.

Have a great rest of the day.
__________________
Thanks,
--Eric

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #114  
Old 06-08-2017, 01:18 PM
mimiph mimiph is offline
Registered User
 
Join Date: Jun 2017
Posts: 2
Hello,

I am trying to run the script but I am getting this error:

Authentication timed out!
(Or you forgot to add a case for a successful shell prompt in the vPossibleShellPrompts array)

I am new to scripting so I'm not sure yet what the exact case to add is.

Thanks!
Reply With Quote
  #115  
Old 06-08-2017, 01:27 PM
ekoranyi ekoranyi is offline
VanDyke Technical Support
 
Join Date: Jan 2017
Posts: 654
Hi mimiph,

I'm sorry to hear you are having trouble. Which version of the script are you attempting to run?

What version of SecureCRT and Operating system are you running?
__________________
Thanks,
--Eric

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #116  
Old 06-08-2017, 01:31 PM
mimiph mimiph is offline
Registered User
 
Join Date: Jun 2017
Posts: 2
Quote:
Originally Posted by ekoranyi View Post
Hi mimiph,

I'm sorry to hear you are having trouble. Which version of the script are you attempting to run?

What version of SecureCRT and Operating system are you running?

I'm running RunCommandsOnMultipleHostsAndLogResults.vbs on SecureCRT 8.1.2 and Windows 7
Reply With Quote
  #117  
Old 06-08-2017, 02:28 PM
ekoranyi ekoranyi is offline
VanDyke Technical Support
 
Join Date: Jan 2017
Posts: 654
Hi mimiph,

Thanks for the additional information.

To better assist you I will need some additional information. For the host that you are having trouble with can you provide a log of a manual successful connection. Due to logs often containing sensitive data I would ask that you provide it via email rather than in the forums. See the below instructions. Once complete please email it to Support@VanDyke.com with "Attn: Eric Forum post 10651" as the subject.


- Launch SecureCRT and open SecureCRT's main "File" menu and select the "Trace Options" menu item.

- Open the "File" menu again and choose "Log Session..."
--> Specify a path to your Desktop folder and a name of the log file, such as SCRT_Log.txt. For example: %APPDATA%\..\..\Desktop\SCRT_Log.txt

- Now attempt your connection again.

- When the connection fails, open SecureCRT's "File" menu and look at the "Log Session" menu item. If it has a check-mark next to it, click on it to turn off logging.

- Go to your Desktop folder and locate the SCRT_Log.txt file. Please send the SCRT_Log.txt file to me as an attachment to your reply. Please don't paste the contents into the body of your message -- please attach it!
__________________
Thanks,
--Eric

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #118  
Old 12-17-2017, 09:33 AM
karthia karthia is offline
Registered User
 
Join Date: Dec 2017
Posts: 3
Unable to run the script

It sends the command before the login completes. Following is example


show ip route 0.0.0.0
alttr201#
Reply With Quote
  #119  
Old 12-18-2017, 08:23 AM
ekoranyi ekoranyi is offline
VanDyke Technical Support
 
Join Date: Jan 2017
Posts: 654
Hi karthia,

I'm sorry you're having trouble. This thread is several months old and several script snippets were posted. Would it be possible for you to provide the full contents of the script you are attempting to run?
__________________
Thanks,
--Eric

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #120  
Old 12-21-2017, 09:25 AM
karthia karthia is offline
Registered User
 
Join Date: Dec 2017
Posts: 3
Here is the script, VBscript

==================

'''
' ReadDataFromHostFile-SendCommandsFromCommandsFile-LogResultsToSingleFile.vbs
' Last Modified: 6 Jun 2013
'
' DESCRIPTION:
' Demonstrates how to connect to hosts and send commands, logging results of
' each command to a single file and a filename based on the current date and
' time that the script is run. Separators are included to help visually
' determine commands that were run and a different separator between each
' host.
'
' Host information is read from a file named "##hosts.txt" (located in
' "Documents" folder)
'
' Commands to be run on each remote host are read in from a file named
' "##commands.txt" (also located in "Documents" folder)
'
' This script does not interfere with a session's logging settings; instead,
' the g_objNewTab.Screen.ReadString() method is used to capture the output of
' a command, and then the built-in Windows FileSystemObject is used to write
' the captured data to a file.
'''

Set g_fso = CreateObject("Scripting.FileSystemObject")
Set g_shell = CreateObject("WScript.Shell")

g_strMyDocs = g_shell.SpecialFolders("MyDocuments")

' ##hosts.txt and ##commands.txt files are located in the current user's
' ##MyDocuments folder. Hard-code to different paths as your needs dictate.
g_strHostsFile = g_strMyDocs & "\##hosts.txt"
g_strCommandsFile = g_strMyDocs & "\##commands.txt"

' Template used for formulating the name of the results file in which the
' command output will be saved. You can choose to arrange the various
' components (i.e. "YYYY", "MM", "DD", "hh", etc.) of the log file name
' into whatever order you want it to be.
g_strOutputFile = g_strMyDocs & "\##Output_Results--YYYY-MM-DD--hh'mm'ss.txt"

' Add Time stats to the log file name based on the Template
' defined by the script author.
g_strOutputFile = Replace(g_strOutputFile, "YYYY-", Year(Date) & "-")
g_strOutputFile = Replace(g_strOutputFile, "-MM-", "-" & NN(Month(Date)) & "-")
g_strOutputFile = Replace(g_strOutputFile, "-DD-", "-" & NN(Day(Date)) & "-")
g_strOutputFile = Replace(g_strOutputFile, "-hh'", "-" & NN(Hour(Time)) & "'")
g_strOutputFile = Replace(g_strOutputFile, "'mm'", "'" & NN(Minute(Time)) & "'")
g_strOutputFile = Replace(g_strOutputFile, "'ss", "'" & NN(Second(Time)))

' Comment character allows for comments to exist in either the host.txt or
' commands.txt files. Lines beginning with this character will be ignored.
g_strComment = "#"

' If connecting through a proxy is required, comment out the second statement
' below, and modify the first statement below to match the name of the firewall
' through which you're connecting (as defined in global options within
' SecureCRT)
g_strFirewall = " /FIREWALL=myFireWallName "
g_strFirewall = ""

' Username for authenticating to the remote system
g_strUsername = "U$3R"
' Password for authenticating to the remote system
g_strPassword = "P@$$w0Rd"

' Global variable for housing details of any errors that might be encountered
g_strError = ""

' Constants used for reading and writing files.
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8

Dim g_objNewTab, g_strHost

' Call the main subroutine named "MainSub"
MainSub

'-------------------------------------------------------------------------------
Sub MainSub()

' Create arrays in which lines from the hosts and commands files will be
' stored.
Dim vHosts(), vCommands()
' Create variables for storing information about the lines read from the
' file
Dim nHostCount, nCommandCount, nCommentLines
' Call the ReadDataFromFile() function defined in this script. It will
' read in the hosts file and populate an array with non-comment lines that
' will represent the hosts to which connections will be made later on.
If Not ReadDataFromFile(g_strHostsFile, _
g_strComment, _
vHosts, _
nHostCount, _
nCommentLines) Then
DisplayMessage "No hosts were found in file: " & vbcrlf & _
vbtab & g_strHostsFile
Exit Sub
End If

' Now call the ReadDataFromFile() function for the commands file.
If Not ReadDataFromFile(g_strCommandsFile, _
g_strComment, _
vCommands, _
nCommandCount, _
nCommentLines) Then
DisplayMessage "No commands were found in file: " & vbcrlf & _
vbtab & g_strCommandsFile
Exit Sub
End If

Dim strErrors, strSuccesses

' Before attempting any connections, ensure that the "Auth Prompts In
' Window" option in the Default session is already enabled. If not, prompt
' the user to have the script enable it automatically before continuing.
' Before continuing on with the script, ensure that the session option
' for handling authentication within the terminal window is enabled
Set objConfig = crt.OpenSessionConfiguration("Default")
bAuthInTerminal = objConfig.GetOption("Auth Prompts In Window")
If Not bAuthInTerminal Then
strMessage = _
"The 'Default' session (used for all ad hoc " & _
"connections) does not have the ""Display logon prompts in " & _
"terminal window"" option enabled, which is required for this " & _
"script to operate successfully." & vbcrlf & vbcrlf
If PromptYesNo(_
strMessage & _
"Would you like to have this script automatically enable this " & _
"option in the 'Default' session so that next time you run " & _
"this script, the option will already be enabled?") <> vbYes Then
Exit Sub
End If

' User answered prompt with Yes, so let's set the option and save
objConfig.SetOption "Auth Prompts In Window", True
objConfig.Save
End If


' Iterate through each element of our vHosts array...
For nIndex = 0 To nHostCount - 1
' Arrays are indexed starting at 0 (zero)

' Store the current host in a variable so we don't have to remember
' what "vHosts(nIndex)" means.
g_strHost = vHosts(nIndex)

' Exit the loop if the host name is empty (this means we've
' reached the end of our array
If g_strHost = "" Then Exit For

' Build up a string containing connection information and options.
' /ACCEPTHOSTKEYS should only be used if you suspect that there might be
' hosts in the hosts.txt file to which you haven't connected before, and
' therefore SecureCRT hasn't saved out the SSH2 server's host key. If
' you are confused about what a host key is, please read through the
' white paper:
' http://www.vandyke.com/solutions/host_keys/index.html
'
' A best practice would be to connect manually to each device,
' verifying each server's hostkey individually before running this
' script.
'
' If you want to authenticate with publickey authentication instead of
' password, in the assignment of strConnectString below, replace:
' " /AUTH password,keyboard-interactive /PASSWORD " & g_strPassword & _
' with:
' " /AUTH publickey /I ""full_path_to_private_key_file"" " & _
strConnectString = _
g_strFirewall & _
" /SSH2 " & _
" /L " & g_strUsername & _
" /AUTH password,keyboard-interactive /PASSWORD " & g_strPassword & _
" " & g_strHost

' Call the Connect() function defined below in this script. It handles
' the connection process, returning success/fail.
If Not Connect(strConnectString) Then
strErrors = strErrors & vbcrlf & _
vbtab & "Failed to connect to " & g_strHost & _
": " & g_strError
Else
' If we get to this point in the script, we're connected (including
' authentication) to a remote host successfully.
g_objNewTab.Screen.Synchronous = True
g_objNewTab.Screen.IgnoreEscape = True

' Once the screen contents have stopped changing (polling every
' 350 milliseconds), we'll assume it's safe to start interacting
' with the remote system.
If Not WaitForScreenContentsToStopChanging(350) Then
strErrors = strErrors & vbcrlf & _
"Error: Failed to detect remote ready status for host: " & _
g_strHost & ". " & g_strError
Else
' Get the shell prompt so that we can know what to look for when
' determining if the command is completed. Won't work if the
' prompt is dynamic (e.g. changes according to current working
' folder, etc)
nRow = g_objNewTab.Screen.CurrentRow
strPrompt = g_objNewTab.Screen.Get(nRow, _
0, _
nRow, _
g_objNewTab.Screen.CurrentColumn - 1)
strPrompt = Trim(strPrompt)

' Open output file so we can write results to it
Dim objFile
Set objFile = g_fso.OpenTextFile(g_strOutputFile, ForAppending, True)

' Send each command one-by-one to the remote system:
For Each strCommand In vCommands
If strCommand = "" Then Exit For

' Send the command text to the remote
g_objNewTab.Screen.Send strCommand & vbcr

' Wait for the command to be echo'd back to us.
g_objNewTab.Screen.WaitForString strCommand

' Since we don't know if we're connecting to a cisco switch or a
' linux box or whatever, let's look for either a Carriage Return
' (CR) or a Line Feed (LF) character in any order.
vWaitFors = Array(vbcr, vblf)
bFoundEOLMarker = False
Do
' Call WaitForStrings, passing in the array of possible
' matches.
g_objNewTab.Screen.WaitForStrings vWaitFors, 1

' Determine what to do based on what was found)
Select Case g_objNewTab.Screen.MatchIndex
Case 0 ' Timed out
Exit Do

Case 1,2 ' found either CR or LF
' Check to see if we've already seen the other
' EOL Marker
If bFoundEOLMarker Then Exit Do

' If this is the first time we've been through
' here, indicate as much, and then loop back up
' to the top and try to find the other EOL
' marker.
bFoundEOLMarker = True
End Select
Loop

' Now that we know the command has been sent to the remote
' system, we'll begin the process of capturing the output of
' the command.

Dim strResult
' Use the ReadString() method to get the text displayed
' while the command was runnning. Note that the ReadString
' usage shown below is not documented properly in SecureCRT
' help files included in SecureCRT versions prior to 6.0
' Official. Note also that the ReadString() method captures
' escape sequences sent from the remote machine as well as
' displayed text. As mentioned earlier in comments above,
' if you want to suppress escape sequences from being
' captured, set the Screen.IgnoreEscape property = True.
strResult = g_objNewTab.Screen.ReadString(strPrompt)

' If you want the command logged along with the results,
' uncomment the next two lines
' objFile.WriteLine "Results of command """ & strCommand & _
' """ sent to host """ & g_strHost & """: "

' Write out the results of the command and a separator
objFile.WriteLine strResult

' Add a separator between commands
objFile.WriteLine _
"- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -"

Next ' Command Loop

' Add a separator between hosts
objFile.WriteLine String(80, "=")

' Close the log file
objFile.Close

' Now disconnect from the current machine before connecting to
' the next machine
Do
g_objNewTab.Session.Disconnect
crt.Sleep 100
Loop While g_objNewTab.Session.Connected

strSuccesses = strSuccesses & vbcrlf & g_strHost
End If ' WaitForScreenContentsToStopChanging()
End If ' Connect()

Next ' Host Loop

strMsg = "Commands were sent to the following hosts: " & _
vbcrlf & strSuccesses

If strErrors <> "" Then
strMsg = strMsg & vbcrlf & vbcrlf & _
"Errors were encountered connecting to these hosts:" & _
vbcrlf & strErrors
End If

DisplayMessage strMsg
End Sub


'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Function ReadDataFromFile(strFile, _
strComment, _
ByRef vLines, _
ByRef nLineCount, _
ByRef nCommentLines)
' Returns True if the file was found.
' strFile: IN parameter specifying full path to data file.
' strComment: IN parameter specifying string that preceded
' by 0 or more space characters will indicate
' that the line should be ignored.
' vLines: OUT parameter (destructive) containing array
' of lines read in from file.
' nLineCount: OUT parameter (destructive) indicating number
' of lines read in from file.
' nCommentLines: OUT parameter (destructive) indicating number
' of comment/blank lines found
'
'
' Check to see if the file exists... if not, bail early.
If Not g_fso.FileExists(strFile) Then
DisplayMessage "File not found: " & strFile
Exit Function
End If

' Start of with a reasonable size for the array:
ReDim vLines(5)

' Open a TextStream Object to the file...
Set objTextStream = g_fso.OpenTextFile(strFile, 1, False)

' Used for detecting comment lines, a regular expression object
Set re = New RegExp
re.Pattern = "(^[ \t]*(?:" & strComment & ")+.*$)|(^[ \t]+$)|(^$)"
re.Multiline = False
re.IgnoreCase = False

' Now read in each line of the file and add an element to
' the array for each line that isn't just spaces...
nLineCount = 0
nCommentLines = 0

Do While Not objTextStream.AtEndOfStream
strLine = ""

' Find out if we need to make our array bigger yet
' to accommodate all the lines in the file. For large
' files, this can be very memory-intensive.
If UBound(vLines) >= nLineCount Then
ReDim Preserve vLines(nLineCount + 5)
End If

strLine = Trim(objTextStream.ReadLine)

' Look for comment lines that match the pattern
' [whitespace][strComment]
If re.Test(strLine) Then
' Line matches our comment pattern... ignore it
nCommentLines = nCommentLines + 1
Else
vLines(nLineCount) = strLine
nLineCount = nLineCount + 1
End If
Loop

objTextStream.Close

ReadDataFromFile = True
End Function

'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Function Connect(strConnectInfo)
' Connect in a new tab to the host specified
bWaitForAuthToCompleteBeforeReturning = False
bLetCallerDetectAndHandleConnectionErrors = True
Set g_objNewTab = crt.Session.ConnectInTab( _
strConnectInfo, _
bWaitForAuthToCompleteBeforeReturning, _
bLetCallerDetectAndHandleConnectionErrors)

If g_objNewTab.Session.Connected <> True Then
If g_objNewTab.GetLastErrorMessage = "" Then
g_strError = "Unknown error"
Else
g_strError = g_objNewTab.GetLastErrorMessage
End If

' You're not allowed to close the script tab (the tab in which the
' script was launched oringinally), so only try if the new tab really
' was a new tab -- not just reusing a disconnected tab.
If g_objNewTab.Index <> crt.GetScriptTab().Index Then g_objNewTab.Close
Exit Function
End If

' Make sure the new tab is "Synchronous" so we can properly wait/send/etc.
g_objNewTab.Screen.Synchronous = True

' Handle authentication in the new tab using the new tab's object reference
' instead of 'crt'
nAuthTimeout = 10 ' seconds

' Modify the "$", the "]#", and/or the "->" in the array below to reflect
' the variety of legitimate shell prompts you would expect to see when
' authentication is successful to one of your remote machines.
vPossibleShellPrompts = Array(_
"ogin:", _
"name:", _
"sword:", _
"Login incorrect", _
"authentication failed.", _
"$", _
"#", _
">")

Do
On Error Resume Next
g_objNewTab.Screen.WaitForStrings vPossibleShellPrompts, nAuthTimeout
nError = Err.Number
strErr = Err.Description
On Error Goto 0
' Most likely if there was a problem here, it would have been caused by
' an unexpected disconnect occurring while WaitForStrings() was running
' as called above. If error, set the global description variable and
' then exit the function.
If nError <> 0 Then
g_strError = Err.Description

' Ensure that the session is disconnected before we exit this
' function. If there are subsequent hosts to loop through, we don't
' want a connected tab interfering with the next host's connection
' attempts
Do
objNewTab.Session.Disconnect
crt.Sleep 100
Loop While g_objNewTab.Session.Connected

Exit Function
End If

' This Select..Case statement represents somewhat of a "state machine"
' in which the value of Screen.MatchIndex represents the index of the
' array of strings we told WaitForStrings() to look for. Based on this
' index, we know what action needs to be performed next.
Select Case g_objNewTab.Screen.MatchIndex
Case 0
g_strError = "Authentication timed out!" & vbcrlf & _
"(Or you forgot to add a case for a successful shell " & _
"prompt in the vPossibleShellPrompts array)"
' Disconnect from the host so that we can reuse the disconnected
' tab for the next connection in the loop
Do
g_objNewTab.Session.Disconnect
crt.Sleep 100
Loop While g_objNewTab.Session.Connected

Exit Function

Case 1,2 ' "ogin:", "name:"
' Send the username
g_objNewTab.Screen.Send g_strUsername & vbcr

Case 3 ' "sword:"
' Send the password
g_objNewTab.Screen.Send g_strPassword & vbcr

Case 4,5 ' "Login incorrect", "authentication failed."
g_strError = _
"Password authentication to '" & g_strHost & "' as user '" & _
g_strUsername & "' failed." & vbcrlf & vbcrlf & _
"Please specify the correct password for user " & _
"'" & g_strUsername & "'"

' Disconnect from the host so that we can reuse the disconnected
' tab for the next connection in the loop
Do
g_objNewTab.Session.Disconnect
crt.Sleep 100
Loop While g_objNewTab.Session.Connected

Exit Function

Case 6,7,8 ' "$", "#", or ">" <-- Shell prompt means auth success
g_objNewTab.Session.SetStatusText _
"Connected to " & g_strHost & " as " & g_strUsername
Exit Do

Case Else
g_strError = _
"Ooops! Looks like you forgot to add code " & _
"to handle this index: " & g_objNewTab.Screen.MatchIndex & _
vbcrlf & _
vbcrlf & _
"Modify your script code's ""Select Case"" block " & _
"to have 'Case' statements for all of the strings you " & _
"are passing to the ""WaitForStrings"" method."

Do
g_objNewTab.Session.Disconnect
crt.Sleep 100
Loop While g_objNewTab.Session.Connected

Exit Function
End Select
Loop

' If the code gets here, then we must have been successful connecting and
' authenticating to the remote machine; Assign True as the return value
' for the Connect() function.
Connect = True
End Function

' -----------------------------------------------------------------------------
Function WaitForScreenContentsToStopChanging(nMsDataReceiveWindow)
' This function relies on new data received being different from the
' data that was already received. It won't work if, as one example, you
' have a screenful of 'A's and more 'A's arrive (because one screen
' "capture" will look exactly like the previous screen "capture").

' Store Synch flag for later restoration
bOrig = g_objNewTab.Screen.Synchronous
' Turn Synch off since speed is of the essence; we'll turn it back on (if
' it was already on) at the end of this function
g_objNewTab.Screen.Synchronous = False

' Be "safe" about trying to access Screen.Get(). If for any reason we
' get disconnected, we don't want the script to error out on the problem
' so we'll just return false and handle writing something to our log
' file for this host.
On Error Resume Next
strLastScreen = g_objNewTab.Screen.Get(1,1,g_objNewTab.Screen.Rows,g_objNewTab.Screen.Columns)
nError = Err.Number
strErr = Err.Description
On Error Goto 0
If nError <> 0 Then
g_strError = strErr
Exit Function
End If
Do
crt.Sleep nMsDataReceiveWindow

' Be "safe" about trying to access Screen.Get(). If for any reason we
' get disconnected, we don't want the script to error out on the problem
' so we'll just return false and handle writing something to our log
' file for this host.
On Error Resume Next
strNewScreen = g_objNewTab.Screen.Get(1,1,g_objNewTab.Screen.Rows, g_objNewTab.Screen.Columns)
nError = Err.Number
strErr = Err.Description
On Error Goto 0
If nError <> 0 Then
g_strError = strErr
Exit Function
End If

If strNewScreen = strLastScreen Then Exit Do

strLastScreen = strNewScreen
Loop

WaitForScreenContentsToStopChanging = True
' Restore the Synch setting
g_objNewTab.Screen.Synchronous = bOrig
End Function



'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Function NN(nNumber)
' Normalizes a single digit number into a double-digit number with a leading 0
If Len(nNumber) < 2 Then nNumber = "0" & nNumber
NN = nNumber
End Function

'-------------------------------------------------------------------------------
Function PromptYesNo(strText)
PromptYesNo = crt.Dialog.MessageBox(strText, "SecureCRT", vbYesNo)
End Function

'-------------------------------------------------------------------------------
Function DisplayMessage(strText)
crt.Dialog.MessageBox strText
End Function

====================================

Please help me with modifications.

Last edited by ekoranyi; 12-21-2017 at 09:32 AM.
Reply With Quote
Reply

Tags
example script


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