Welcome to the VanDyke Software Forums

Join the discussion today!

Go Back   VanDyke Software Forums > Scripting


Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
Old 10-21-2015, 06:48 AM
umbongo umbongo is offline
Registered User
Join Date: Oct 2015
Posts: 13
Post Synchronous behaviour not experienced when using SSH on jumpserver

I have been trying to write a script that examines the software type on various routers and have come across a discrepancy in expected behaviour between telnet and SSH connections. The synchronous property does not seem to have an affect on SSH sessions while it does for telnet sessions. The stranger part of this problem is that I am using a jump server so I would have expected SecureCRT to be agnostic as to what protocol is being used.
I have enabled Synchronous as true on the screen object.
I have thoroughly read through the published scripting guide, which even mentions SSH as part of the example.

Here is a cut-down version of the script I'm using the exhibits the behaviour I'm describing:

Sub Main()
	Dim objTab
	Dim UID
	Dim Router
	Dim protocol
	Dim Password
	Router = "router"
	protocol = "SSH"
	Password = "password"
	UID = "user"
	Set objTab = crt.GetScriptTab
	objTab.Screen.Synchronous = True
	vPossiblePrompts = Array(_
		Router + "#",_
		Router + "-re0>",_
		Router + "-re1>")
	Select Case protocol
		Case "Telnet"
			cnxnString = "telnet " & Router
		Case "SSH"
			cnxnString = "ssh " & "-P " & Password & " " & UID & "@" & Router 
	End Select 

	objTab.Screen.Send cnxnString & chr(13)
	If protocol = "Telnet" then
		objTab.Screen.WaitForStrings "sername:","ogin:"
		objTab.Screen.Send UID & chr(13)
		objTab.Screen.WaitForString "assword:"
		objTab.Screen.Send Password & chr(13)
	End If
	objTab.Screen.WaitForStrings vPossiblePrompts
	objTab.Screen.Send "sh ver " + chr(124) + " i Cisco.*[I-]OS" + chr(13)
	objTab.Screen.WaitForStrings vPossiblePrompts
	screenrow = objTab.Screen.CurrentRow
	screenrow = screenrow - 1
	tempDevice = objTab.Screen.Get(screenrow, 1, screenrow, 80 )
	DeviceType = "undefinied"
	If instr(tempDevice,"IOS") > 0 then
		DeviceType = "IOS"
	End If		
	If instr(tempDevice,"IOS-XE") > 0 then
		DeviceType = "IOS-XE"
	End If		
	If instr(tempDevice,"Nexus") > 0 then
		DeviceType = "NX-OS"
	End If
	MsgBox "tempDevice is " & tempDevice
	MsgBox "DeviceType is " & DeviceType
	objTab.Screen.Send "exit" & chr(13)
End Sub

When connecting using the Telnet protocol everything works as expected. When using SSH the 'tempDevice' variable returns with the line directly above the command prompt immediately after logging in to the device. I have checked the output difference between telnet and SSH and the SSH output contains no unexpected matches within the "vPossiblePrompts" variable that could be causing the WaitForStrings to continue unexpectedly. When the message boxes are dismissed the commands run as expected.

The output of the SSH session is as follows:

$ ssh -P password user@router

* *
* You are authorized to use this System for approved business purposes only. *
* Use for any other purpose is prohibited. All transactional records, reports, *
* e-mail, software, and other data generated by or residing upon this System *
* are the property of the Company and may be used by the Company for any *
* purpose. Authorized and unauthorized activities may be monitored. *
* *

Cisco Nexus Operating System (NX-OS) Software
TAC support: http://www.cisco.com/tac
Copyright (C) 2002-2015, Cisco and/or its affiliates.
All rights reserved.
The copyrights to certain works contained in this software are
owned by other third parties and used and distributed under their own
licenses, such as open source. This software is provided "as is," and unless
otherwise stated, there is no warranty, express or implied, including but not
limited to warranties of merchantability and fitness for a particular purpose.
Certain components of this software are licensed under
the GNU General Public License (GPL) version 2.0 or
GNU General Public License (GPL) version 3.0 or the GNU
Lesser General Public License (LGPL) Version 2.1 or
Lesser General Public License (LGPL) Version 2.0.
A copy of each such license is available at
http://www.opensource.org/licenses/gpl-2.0.php and
http://opensource.org/licenses/gpl-3.0.html and
http://www.opensource.org/licenses/lgpl-2.1.php and
router# sh ver | i Cisco.*[I-]OS <------ Text boxes display at this line before the command is typed
Cisco Nexus Operating System (NX-OS) Software
router# exit

SecureCRT 7.2.3 build 500
Windows 7

Thanks in advance

scripting , ssh , synchronous

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 01:02 PM.