#16
|
|||
|
|||
Logging not working
Quote:
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 |
#17
|
|||
|
|||
Hi mohenoun,
Please post a screenshot of the error you get.
__________________
Thanks, --Brenda VanDyke Software Technical Support support@vandyke.com (505) 332-5730 |
#18
|
|||
|
|||
No error
I don't get any error, I just get a new window to put in the name
|
#19
|
|||
|
|||
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 |
#20
|
|||
|
|||
Screenshot
Quote:
# $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. |
#21
|
|||
|
|||
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 |
#22
|
|||
|
|||
Thank you
Quote:
![]() I thought I attached the screenshot, here it is. |
#23
|
|||
|
|||
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 |
#24
|
|||
|
|||
Is there a way to add a loop within the command section
Quote:
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. |
#25
|
|||
|
|||
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 |
#26
|
|||
|
|||
Error message
Quote:
* 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 ![]() |
#27
|
|||
|
|||
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 |
#28
|
|||
|
|||
Version Version 7
I'm using version 7
|
#29
|
|||
|
|||
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 |
#30
|
|||
|
|||
version 7.0.3
Quote:
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". |
![]() |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
Display Modes | Rate This Thread |
|
|