|
#1
|
|||
|
|||
Issue waiting for string
Hi All,
I tried to create a script by recording and modifying but not able to successful. Basically when I login to any node via SSH command, its ask for line "Are you sure you want to continue connecting (yes/no)?" or line "Enter password:" . In below script I tried to modify into 2 parts with if condition but not succesful Cany anybody help me out what modification required in below code. Code:
#$language = "VBScript" #$interface = "1.0" crt.Screen.Synchronous = True ' This automatically generated script may need to be ' edited in order to work correctly. Sub Main crt.Screen.Send "ssh 00.00.000.00" & chr(13) If crt.Screen.WaitForString ("Are you sure you want to continue connecting (yes/no)? ") = True Then crt.Screen.Send "yes" & chr(13) crt.Screen.WaitForString "Enter password:" crt.Screen.Send "XXXXXX" & chr(13) crt.Screen.WaitForString "<RING-" crt.Screen.Send "scre 0 temp" & chr(13) crt.Screen.WaitForString "<RING-" crt.Screen.Send "dis interface GigabitEthernet " & chr(124) & " i GigabitEthernet" & chr(124) & "Line protocol current state" & chr(124) & "Description" & chr(124) & "IP Sending Frames" & chr(13) crt.Screen.WaitForString "<RING-" crt.Screen.Send "dis arp all" & chr(13) crt.Screen.WaitForString "<RING-" crt.Screen.Send "quit" & chr(13) crt.Screen.WaitForString "[user@user1 " & chr(126) & "]$" Else crt.Screen.WaitForString "Enter password:" crt.Screen.Send "XXXXXX" & chr(13) crt.Screen.WaitForString "<RING-" crt.Screen.Send "scre 0 temp" & chr(13) crt.Screen.WaitForString "<RING-" crt.Screen.Send "dis interface GigabitEthernet " & chr(124) & " i GigabitEthernet" & chr(124) & "Line protocol current state" & chr(124) & "Description" & chr(124) & "IP Sending Frames" & chr(13) crt.Screen.WaitForString "<RING-" crt.Screen.Send "dis arp all" & chr(13) crt.Screen.WaitForString "<RING-" crt.Screen.Send "quit" & chr(13) crt.Screen.WaitForString "[user@user1 " & chr(126) & "]$" End if End Sub |
#2
|
|||
|
|||
Hi Negi1984,
I'm sorry to hear you're having trouble. It sounds to me like you're trying to connect to multiple devices and run a set of commands, is that the case? If so, we have a pretty comprehensive example script that does just that. Run Commands On Multiple Hosts And Log ResultsWith some slight modification it can be configured to automatically accept new host keys if this is the first time you're connecting to a device. Information on making this change is available starting at line 310 of the script. Does this script seem to fit your needs?
__________________
Thanks, --Eric VanDyke Software Technical Support support@vandyke.com (505) 332-5730 |
#3
|
|||
|
|||
Hi ,
Thanks a lot for your valuable suggestion. Actually I am new to VB scripting. I have another template macro file where I am dynamically mapping the above code to different IPs and then run that script. So want to know if the below line code is correct to check if this line exist or not ? If crt.Screen.WaitForString ("Are you sure you want to continue connecting (yes/no)? ") = True |
#4
|
|||
|
|||
Hi Negi1984,
While something like the below code would work, I don't know that it will give you the desired behavior. Code:
If crt.Screen.WaitForString ("test") = True Then crt.Dialog.MessageBox "True" End If Code:
crt.Screen.WaitForString "test" crt.Dialog.MessageBox "True" Code:
#$language = "VBScript" #$interface = "1.0" crt.Screen.Synchronous = True ' Create array of possible prompts vPossiblePrompts = Array(_ "Are you sure you want to continue connecting (yes/no)? ", _ "Enter password:") Sub Main ' Send command and wait for confirmation the command was recieved crt.Screen.Send "ssh 00.00.000.00" & chr(13) crt.Screen.WaitForString chr(13) ' Wait for either (yes/no) or password prompt with 5 second timeout crt.Screen.WaitForStrings vPossiblePrompts, 5 Select Case vPossiblePrompts(crt.Screen.MatchIndex-1) ' In the case of (yes/no) prompt Case "Are you sure you want to continue connecting (yes/no)? " crt.Screen.Send "yes" & chr(13) crt.Screen.WaitForString "Enter password:" ' In the case of timeout Case Else crt.Screen.Send "5 second timeout reached." End Select crt.Screen.Send "XXXXXX" & chr(13) crt.Screen.WaitForString "<RING-" crt.Screen.Send "scre 0 temp" & chr(13) crt.Screen.WaitForString "<RING-" crt.Screen.Send "dis interface GigabitEthernet " & chr(124) & " i GigabitEthernet" & chr(124) & "Line protocol current state" & chr(124) & "Description" & chr(124) & "IP Sending Frames" & chr(13) crt.Screen.WaitForString "<RING-" crt.Screen.Send "dis arp all" & chr(13) crt.Screen.WaitForString "<RING-" crt.Screen.Send "quit" & chr(13) crt.Screen.WaitForString "[user@user1 " & chr(126) & "]$" End Sub
__________________
Thanks, --Eric VanDyke Software Technical Support support@vandyke.com (505) 332-5730 |
#5
|
|||
|
|||
Hi,
Thanks a lot, this is what I am looking for. Only little issue is that After SSH command 2 time Enter Password line coming up. And as soon as I type manually the password , script start running again. I think this is due to extra Enter calling in script after ssh command ? Thanks again for your valuable suggestion. |
#6
|
|||
|
|||
Negi1984,
I'm not sure that I fully understand the issue. Perhaps reviewing a log generated while attempting to run the script will help me get a better understanding of the trouble you're having. PLEASE DO NOT POST YOUR LOG IN THE FORUMS. Can you take these steps and send me the resulting log file for analysis? Video Link: https://youtu.be/kzEUhvxKvyY - 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. - 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 as an email attachment to Support@VanDyke.com with "Attn Eric Forum Post 13389" in the subject line.
__________________
Thanks, --Eric VanDyke Software Technical Support support@vandyke.com (505) 332-5730 |
![]() |
Thread Tools | |
Display Modes | Rate This Thread |
|
|