Welcome to the VanDyke Software Forums

Join the discussion today!


Go Back   VanDyke Software Forums > Scripting

Reply
 
Thread Tools Rate Thread Display Modes
  #16  
Old 11-23-2020, 02:30 AM
mohenoun mohenoun is offline
Registered User
 
Join Date: Nov 2020
Posts: 21
Logging not working

Quote:
Originally Posted by bgagnon View Post
Hi mohenoun,

I provided an example for logging.

If I have any suggestion for reading a file, it won't be until Monday at the earliest. If feeling ambitious, you might just look at how it was done in the RunCommands example and try to add that code to this script.
When I add :
crt.Session.LogFileName = "C:\Users\username\Documents\Log" & vHosts(nIndex) & "-%M%D%y.txt"
crt.Session.Log True

I get a prompt for logging asking me to enter a name for the file
Reply With Quote
  #17  
Old 11-23-2020, 08:54 AM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,520
Hi mohenoun,

Please post a screenshot of the error you get.
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #18  
Old 11-23-2020, 10:33 AM
mohenoun mohenoun is offline
Registered User
 
Join Date: Nov 2020
Posts: 21
No error

Quote:
Originally Posted by bgagnon View Post
Hi mohenoun,

Please post a screenshot of the error you get.
I don't get any error, I just get a new window to put in the name
Attached Images
File Type: png screeshot.PNG (20.6 KB, 23 views)
Reply With Quote
  #19  
Old 11-23-2020, 10:48 AM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,520
Hi mohenoun,

I cannot replicate that.

What is the configuration in your rebound server session with respect to logging in the Terminal / Log File category of Session Options?

Where in the script did you place the logging snippet?
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #20  
Old 11-24-2020, 04:29 AM
mohenoun mohenoun is offline
Registered User
 
Join Date: Nov 2020
Posts: 21
Screenshot

Quote:
Originally Posted by bgagnon View Post
Hi mohenoun,

I cannot replicate that.

What is the configuration in your rebound server session with respect to logging in the Terminal / Log File category of Session Options?

Where in the script did you place the logging snippet?
Here it is :

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

' JumpHost-HandleSecondaryHostConnectionAttempts.vbs
'
' - NOTE: SecureCRT must currently be connected to a gateway machine or
' jump host on which commands can be issued to connect to secondary hosts
' (eg: 'ssh hostb', 'telnet hostc', etc.)

crt.Session.Connect("/s jump.start")
crt.Screen.WaitForString "jumpy#"

crt.Screen.Synchronous = True
vHosts = Array(_
"EQT-PE2",_
"EQT-PE1",_
"EQT-RR",_
"EQT-PE3",_
"EQT-PE4",_
"EQTRR",_
"EQTPE1",_
"EQTPE2",_
"EQT-PE2",_
"EQT-PE1",_
"EQT-PE3",_
"EQT-PE4")

' The order of elements in this array should be in the order of:
' - Expected login prompts (eg: "-->", "#", etc.)
' - Special cases (accept host key, enter pwd, enter username, etc.)
' - Fail/Bail cases (wrong pwd/login, hostname not found, time out, etc.)
vPossibleResponses = Array(_
">",_
"#",_
"ogin:", _
"ame:", _
"(yes/no)?",_
"sword:",_
"Permission denied",_
"Unknown command or computer name, or unable to find computer address", _
"not known", _
"timed out")

nIndex = 0
strJumpHostPrompt = "jumpy#"
Do
strCommand = "ssh -l username " & vHosts(nIndex)
crt.Screen.Send strCommand & vbcr

' Wait for our command to be echoed back to us so we know that it has been
' received before we attempt to wait for all possible responses.
crt.Screen.WaitForString strCommand & vbcr

' Start an inner Do..Loop that looks for all defined possible responses to
' the Telnet... or SSH... command we just sent.
Do
crt.Screen.WaitForStrings vPossibleResponses
If crt.Screen.MatchIndex > 0 Then
strStringFound = vPossibleResponses(crt.Screen.MatchIndex - 1)
End If
Select Case crt.Screen.MatchIndex
Case 1,2
' Found "-->" or "#" which in our example indicate successful
' authentications.

' Do work we need to complete on host including sending the exit
' command which will disconnect us from the secondary host
' allowing us to loop up to the top and connect to the next
' host. Note that the strStringFound variable currently contains
' the "Secondary Host Prompt" if needed.
' .
' .
' .

' Now that we have done the necessary work (including waiting
' for an indication that the last command we sent above has
' completed, send "exit" to disconnect from secondary host.*
'Start by logging
crt.Session.LogFileName = "C:\Users\username\Documents\Log" & vHosts(nIndex) & "-%M%D%y.txt"
crt.Session.Log True
crt.Screen.Send "show ip bgp vpnv4 all summ | inc Idle" & vbcr
crt.Screen.WaitForString "#"
crt.Screen.Send vbcr
crt.Session.Log False
crt.Screen.Send "exit" & vbcr

' Wait for an indication that the exit command was successful
' before attempting to connect to next host.
crt.Screen.WaitForString strJumpHostPrompt

' Exit inner Do..Loop since we are done with the success case.
Exit Do

Case 3,4
' Found "ogin" or "ame" which means waiting for user account.
crt.Screen.Send strUsername & vbcr

' Fall through to the top of the inner Do..Loop to continue
' waiting for strings until all possibilities are exhausted.

Case 5
' Found new hostkey prompt. This indicates that this is the
' first time we have connected to the remote machine, and we
' need to accept the hostkey.
crt.Screen.Send "yes" & vbcr

' Fall through to the top of the inner Do..Loop to continue
' waiting for strings until all possibilities are exhausted.

Case 6
' We are being prompted for a password. Send it.
crt.Screen.Send "Pa$$word" & vbcr

' Fall through to the top of the inner Do..Loop to continue
' waiting for strings until all possibilities are exhausted.

Case 7
' SSH Password was denied or login was incorrect. Exit this
' inner Do..Loop and move on to the next host.

' First cancel the current authentication attempt to the
' secondary host.
crt.Screen.SendKeys "^c"

' Wait for an indication that the Ctrl+C was successful before
' attempting to connect to next host.
crt.Screen.WaitForString strJumpHostPrompt

' Exit inner Do..Loop and move to next host.
Exit Do

Case 8
' Telnet login or password was incorrect. Exit this inner
' Do..Loop and move on to the next host.

' First cancel the current authentication attempt to the
' secondary host.
crt.Screen.SendKeys "^]"
crt.Screen.WaitForString "telnet>"
crt.Screen.Send "quit" & vbcr

' Wait for an indication that the Ctrl+C was successful before
' attempting to connect to next host.
crt.Screen.WaitForString strJumpHostPrompt

' Exit inner Do..Loop and move to next host.
Exit Do

Case 9,10
' Not able to reach secondary host. Connection timed out.
' Wait for primary host prompt before exiting inner Do..Loop.
crt.Screen.WaitForString strJumpHostPrompt

' Exit inner Do..Loop and move to next host.
Exit Do

Case Else
' Let user know that there is an unhandled case
crt.Session.SetStatusText _
"Unhandled """ & strStringFound & """"
' Yikes... Never expect to be here, but if we got here, it's
' probably a programming error you've introduced with the
' 'vPossibleResponses' variable that you'll need to fix
crt.Dialog.MessageBox "Yikes!" & vbcrlf & vbcrlf & _
"We never expect to get here. if you see this, you" & _
vbcrlf & _
"have probably introduced a programming error into" & _
vbcrlf & _
"your script code which will you will need to fix." & _
vbcrlf & vbcrlf & _
"Chances are you added a string to vPossibleResponses " & _
vbcrlf & _
"but you haven't added the code to handle " & _
vbcrlf & _
"what to do when that special string was found:" & _
vbcrlf & vbcrlf & vbtab & """" & strStringFound & """"
crt.Screen.SendSpecial "MENU_SCRIPT_CANCEL"

End Select
Loop ' Inner loop waiting for all possible responses.

nIndex = nIndex + 1

' Exit outer Do..Loop if we have attempted to connect to all hosts.
If nIndex > Ubound(vHosts) Then Exit Do

Loop ' Outer loop connecting to all hosts in array.
Attached Images
File Type: png Log opt.png (50.1 KB, 22 views)
Reply With Quote
  #21  
Old 11-24-2020, 08:39 AM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,520
Hi mohenoun,

You overlooked this question:

What is the configuration in your rebound server session with respect to logging in the Terminal / Log File category of Session Options?

In your logging within the script, you are missing a backslash on the path, but I don't think it would cause this issue:

crt.Session.LogFileName = "C:\Users\username\Documents\Log" & vHosts(nIndex) & "-%M%D%y.txt"

should be:

crt.Session.LogFileName = "C:\Users\username\Documents\Log\" & vHosts(nIndex) & "-%M%D%y.txt"

I am working with my manager on a possible proof of concept of a hybrid script which combines what you need from RunCommands script with the scenario where you are going through a jump host. However, in the course of a day, scripting assistance has to take a back seat priority-wise to other issues deemed more urgent (such as crashes, unexpected behavior, etc.).
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #22  
Old 11-24-2020, 08:51 AM
mohenoun mohenoun is offline
Registered User
 
Join Date: Nov 2020
Posts: 21
Thank you

Quote:
Originally Posted by bgagnon View Post
Hi mohenoun,

You overlooked this question:

What is the configuration in your rebound server session with respect to logging in the Terminal / Log File category of Session Options?

In your logging within the script, you are missing a backslash on the path, but I don't think it would cause this issue:

crt.Session.LogFileName = "C:\Users\username\Documents\Log" & vHosts(nIndex) & "-%M%D%y.txt"

should be:

crt.Session.LogFileName = "C:\Users\username\Documents\Log\" & vHosts(nIndex) & "-%M%D%y.txt"

I am working with my manager on a possible proof of concept of a hybrid script which combines what you need from RunCommands script with the scenario where you are going through a jump host. However, in the course of a day, scripting assistance has to take a back seat priority-wise to other issues deemed more urgent (such as crashes, unexpected behavior, etc.).
I understand thank you.
I thought I attached the screenshot, here it is.
Attached Images
File Type: png Log opt.png (50.1 KB, 15 views)
Reply With Quote
  #23  
Old 11-24-2020, 09:15 AM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,520
Hi mohenoun,

I guess you did. Sorry, I was expecting an answer in text and I overlooked it.

Please clear Log file name field since you are not, in fact, specifying a file. I experimented with various configurations but I don't think I had just a path to a folder in there.
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #24  
Old 11-24-2020, 09:59 AM
mohenoun mohenoun is offline
Registered User
 
Join Date: Nov 2020
Posts: 21
Is there a way to add a loop within the command section

Quote:
Originally Posted by bgagnon View Post
Hi mohenoun,

I guess you did. Sorry, I was expecting an answer in text and I overlooked it.

Please clear Log file name field since you are not, in fact, specifying a file. I experimented with various configurations but I don't think I had just a path to a folder in there.
I'm trying to loop inside the command, because cisco is giving me a "" --More-- " and then I need to hit space to scroll to the next section until a # shows and then I have my ouput and I can exit.


The idea is to do :

Run the command

Wait for " --More-- " on the screen then escape
Wait for the next "" --More-- "" then escape
If "#" shows up exit.

I want to add this in the bold section below.

Thanks.

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

' JumpHost-HandleSecondaryHostConnectionAttempts.vbs
'
' - NOTE: SecureCRT must currently be connected to a gateway machine or
' jump host on which commands can be issued to connect to secondary hosts
' (eg: 'ssh hostb', 'telnet hostc', etc.)

crt.Session.Connect("/s jump.start")
crt.Screen.WaitForString "jumpy#"

crt.Screen.Synchronous = True
vHosts = Array(_
"EQT-PE2",_
"EQT-PE1",_
"EQT-RR",_
"EQT-PE3",_
"EQT-PE4",_
"EQTRR",_
"EQTPE1",_
"EQTPE2",_
"EQT-PE2",_
"EQT-PE1",_
"EQT-PE3",_
"EQT-PE4")

' The order of elements in this array should be in the order of:
' - Expected login prompts (eg: "-->", "#", etc.)
' - Special cases (accept host key, enter pwd, enter username, etc.)
' - Fail/Bail cases (wrong pwd/login, hostname not found, time out, etc.)
vPossibleResponses = Array(_
">",_
"#",_
"ogin:", _
"ame:", _
"(yes/no)?",_
"sword:",_
"Permission denied",_
"Unknown command or computer name, or unable to find computer address", _
"not known", _
"timed out")

nIndex = 0
strJumpHostPrompt = "jumpy#"
Do
strCommand = "ssh -l username " & vHosts(nIndex)
crt.Screen.Send strCommand & vbcr

' Wait for our command to be echoed back to us so we know that it has been
' received before we attempt to wait for all possible responses.
crt.Screen.WaitForString strCommand & vbcr

' Start an inner Do..Loop that looks for all defined possible responses to
' the Telnet... or SSH... command we just sent.
Do
crt.Screen.WaitForStrings vPossibleResponses
If crt.Screen.MatchIndex > 0 Then
strStringFound = vPossibleResponses(crt.Screen.MatchIndex - 1)
End If
Select Case crt.Screen.MatchIndex
Case 1,2
' Found "-->" or "#" which in our example indicate successful
' authentications.

' Do work we need to complete on host including sending the exit
' command which will disconnect us from the secondary host
' allowing us to loop up to the top and connect to the next
' host. Note that the strStringFound variable currently contains
' the "Secondary Host Prompt" if needed.
' .
' .
' .

' Now that we have done the necessary work (including waiting
' for an indication that the last command we sent above has
' completed, send "exit" to disconnect from secondary host.*
'Start by logging
crt.Session.LogFileName = "C:\Users\username\Documents\Log" & vHosts(nIndex) & "-%M%D%y.txt"
crt.Session.Log True
crt.Screen.Send "show ip bgp vpnv4 all summ | inc Idle" & vbcr
crt.Screen.WaitForString "#"
crt.Screen.Send vbcr
crt.Session.Log False
crt.Screen.Send "exit" & vbcr


' Wait for an indication that the exit command was successful
' before attempting to connect to next host.
crt.Screen.WaitForString strJumpHostPrompt

' Exit inner Do..Loop since we are done with the success case.
Exit Do

Case 3,4
' Found "ogin" or "ame" which means waiting for user account.
crt.Screen.Send strUsername & vbcr

' Fall through to the top of the inner Do..Loop to continue
' waiting for strings until all possibilities are exhausted.

Case 5
' Found new hostkey prompt. This indicates that this is the
' first time we have connected to the remote machine, and we
' need to accept the hostkey.
crt.Screen.Send "yes" & vbcr

' Fall through to the top of the inner Do..Loop to continue
' waiting for strings until all possibilities are exhausted.

Case 6
' We are being prompted for a password. Send it.
crt.Screen.Send "Pa$$word" & vbcr

' Fall through to the top of the inner Do..Loop to continue
' waiting for strings until all possibilities are exhausted.

Case 7
' SSH Password was denied or login was incorrect. Exit this
' inner Do..Loop and move on to the next host.

' First cancel the current authentication attempt to the
' secondary host.
crt.Screen.SendKeys "^c"

' Wait for an indication that the Ctrl+C was successful before
' attempting to connect to next host.
crt.Screen.WaitForString strJumpHostPrompt

' Exit inner Do..Loop and move to next host.
Exit Do

Case 8
' Telnet login or password was incorrect. Exit this inner
' Do..Loop and move on to the next host.

' First cancel the current authentication attempt to the
' secondary host.
crt.Screen.SendKeys "^]"
crt.Screen.WaitForString "telnet>"
crt.Screen.Send "quit" & vbcr

' Wait for an indication that the Ctrl+C was successful before
' attempting to connect to next host.
crt.Screen.WaitForString strJumpHostPrompt

' Exit inner Do..Loop and move to next host.
Exit Do

Case 9,10
' Not able to reach secondary host. Connection timed out.
' Wait for primary host prompt before exiting inner Do..Loop.
crt.Screen.WaitForString strJumpHostPrompt

' Exit inner Do..Loop and move to next host.
Exit Do

Case Else
' Let user know that there is an unhandled case
crt.Session.SetStatusText _
"Unhandled """ & strStringFound & """"
' Yikes... Never expect to be here, but if we got here, it's
' probably a programming error you've introduced with the
' 'vPossibleResponses' variable that you'll need to fix
crt.Dialog.MessageBox "Yikes!" & vbcrlf & vbcrlf & _
"We never expect to get here. if you see this, you" & _
vbcrlf & _
"have probably introduced a programming error into" & _
vbcrlf & _
"your script code which will you will need to fix." & _
vbcrlf & vbcrlf & _
"Chances are you added a string to vPossibleResponses " & _
vbcrlf & _
"but you haven't added the code to handle " & _
vbcrlf & _
"what to do when that special string was found:" & _
vbcrlf & vbcrlf & vbtab & """" & strStringFound & """"
crt.Screen.SendSpecial "MENU_SCRIPT_CANCEL"

End Select
Loop ' Inner loop waiting for all possible responses.

nIndex = nIndex + 1

' Exit outer Do..Loop if we have attempted to connect to all hosts.
If nIndex > Ubound(vHosts) Then Exit Do

Loop ' Outer loop connecting to all hosts in array.
Reply With Quote
  #25  
Old 11-24-2020, 10:41 AM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,520
Hi mohenoun,

So as I might have mentioned earlier, we do NOT write custom scripts. However, we did feel that there might be a trend towards needing the jump host scenario more frequently in the future so we put together something that might work in that sort of environment. The credit goes to my manager, Jake.

From using this script before I think you know where to make the user/password changes. Line 408 is going to be where you need to specify the Jump Host Session.

I did have to comment out other logging options in order to get "log files per host in a jump host scenario" to work. There's probably a more elegant way to handle the three different options and I'll consult with my manager on his return.

As always, test this example script in a very narrow framework initially. Once you are convinced it does what you need, you can probably then safely load up your hosts file.
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #26  
Old 11-26-2020, 10:13 AM
mohenoun mohenoun is offline
Registered User
 
Join Date: Nov 2020
Posts: 21
Error message

Quote:
Originally Posted by bgagnon View Post
Hi mohenoun,

So as I might have mentioned earlier, we do NOT write custom scripts. However, we did feel that there might be a trend towards needing the jump host scenario more frequently in the future so we put together something that might work in that sort of environment. The credit goes to my manager, Jake.

From using this script before I think you know where to make the user/password changes. Line 408 is going to be where you need to specify the Jump Host Session.

I did have to comment out other logging options in order to get "log files per host in a jump host scenario" to work. There's probably a more elegant way to handle the three different options and I'll consult with my manager on his return.

As always, test this example script in a very narrow framework initially. Once you are convinced it does what you need, you can probably then safely load up your hosts file.
Thank you a lot for the exception you made.
*
I tried the script but I'm getting an error.

I connected directly to the jumpstart and launched the script.

Put in my user and password for the machines in vhosts

and changed jumpstart$ to the correct string.

I took some time to try and figure out the problem, but I couldn't see it.

Can you advise please
Attached Images
File Type: png Vandyke error.PNG (8.3 KB, 16 views)
Reply With Quote
  #27  
Old 11-30-2020, 08:01 AM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,520
Hi mohenoun,

What version of SecureCRT are you using?

If older than v8.7 (or if you have migrated an older config), then change the line in the script that references the Upload Directory to just that, no "V2".
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #28  
Old 11-30-2020, 10:39 AM
mohenoun mohenoun is offline
Registered User
 
Join Date: Nov 2020
Posts: 21
Version Version 7

Quote:
Originally Posted by bgagnon View Post
Hi mohenoun,

What version of SecureCRT are you using?

If older than v8.7 (or if you have migrated an older config), then change the line in the script that references the Upload Directory to just that, no "V2".
I'm using version 7
Reply With Quote
  #29  
Old 11-30-2020, 11:32 AM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,520
Hi mohenoun,

All are old, but please be specific. We released v7.0, v7.1, v7.2, v7.3.
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #30  
Old 12-01-2020, 07:21 AM
mohenoun mohenoun is offline
Registered User
 
Join Date: Nov 2020
Posts: 21
version 7.0.3

Quote:
Originally Posted by bgagnon View Post
Hi mohenoun,

All are old, but please be specific. We released v7.0, v7.1, v7.2, v7.3.

I'm on 7.0.3

I didn't understand the comment below :

If older than v8.7 (or if you have migrated an older config), then change the line in the script that references the Upload Directory to just that, no "V2".
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 12:39 AM.