Welcome to the VanDyke Software Forums

Join the discussion today!


Go Back   VanDyke Software Forums > Scripting

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 02-04-2019, 11:33 AM
Negi1984 Negi1984 is offline
Registered User
 
Join Date: Mar 2015
Posts: 12
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
Reply With Quote
  #2  
Old 02-04-2019, 01:07 PM
ekoranyi ekoranyi is offline
VanDyke Technical Support
 
Join Date: Jan 2017
Posts: 654
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 Results
With 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
Reply With Quote
  #3  
Old 02-05-2019, 06:21 AM
Negi1984 Negi1984 is offline
Registered User
 
Join Date: Mar 2015
Posts: 12
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
Reply With Quote
  #4  
Old 02-05-2019, 08:27 AM
ekoranyi ekoranyi is offline
VanDyke Technical Support
 
Join Date: Jan 2017
Posts: 654
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
Without a timeout configured the script will wait forever until it sees the "test" string. This means that it will just wait until it's True, you'll never get a false value. If this is your goal you can simplify this by using something like:
Code:
crt.Screen.WaitForString "test"
crt.Dialog.MessageBox "True"
In your case it sounds like there a couple of different strings you would like to wait for and you need to vary the behavior depending on the string received. One option to get this behavior would be to use the WaitForStrings method to wait for both strings, then use a Select statement to change the behavior based on which is received.

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
Reply With Quote
  #5  
Old 02-05-2019, 09:07 AM
Negi1984 Negi1984 is offline
Registered User
 
Join Date: Mar 2015
Posts: 12
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.
Reply With Quote
  #6  
Old 02-05-2019, 09:35 AM
ekoranyi ekoranyi is offline
VanDyke Technical Support
 
Join Date: Jan 2017
Posts: 654
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
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 02:24 AM.