Welcome to the VanDyke Software Forums

Join the discussion today!

Go Back   VanDyke Software Forums > Scripting


Thread Tools Rate Thread Display Modes
Old 01-26-2013, 11:22 PM
francc francc is offline
Registered User
Join Date: Nov 2012
Posts: 3
merging 2 script for huawei equipment

Hello all.

I am as some of you know bussy creating a script with my little knowlegde of scripting..

As of now, i have found 2 scripts that does the work what i need, but not all of it.

1 script does evrything i need, but hangs on sending the username.
The second script i have found, does the login to the huawei devices, but notting more.

My idea was to merge the 2 scripts so i could have 1 super great script.
My question is, how can i merge the 2 scripts, to have the final script,
getting me to login automaticly to the devices, based on the hostlist.
PS: the connection MUST be via ssh2.

I found both of the scripts on this forum (so, naturaly all the credit goes to the creators).

Here is the script that actualy logins to the devices:

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

' Connect to an SSH server using the SSH2 protocol. Specify the
' username and password and hostname on the command line as well as
' some SSH2 protocol specific options.

Sub Main

Dim user
user = "username"

' Prompt for a password instead of embedding it in a script...
Dim passwd
passwd = "$L"
cmd = "/SSH2 /L " & user & " /PASSWORD " & passwd & " /C 3DES /M MD5 " & host
crt.Session.Connect cmd
Dim huawei
huawei = crt.Screen.WaitForStrings("ME60",1)
I can login automaticly and send commands to the equipment with this script (i removed the send command option).

I am able to load host from a host file, and create a log file. I cannot login with that script. I have tried to remove the login part (Dim LoginUserName, Dim LoginUserPassword) but then again, it provides me with this error:
"Error syntax error:
line 82,
call LoginME(LoginUserName, LoginUserPassword,)

I have no problem at all to solve this issue with DIM=password and DIM=username, as the script is only to be run internaly (with other words, put the username and password within the script, we will create a read only user for this script to run).

PS this is not my script. The final script will be posted here for others to use as they fit.
Is there a way to solve this issue? Below is the original script altered:

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

' This script is written by Charlee and is under General Public License (GPL)
' Thanks to Rtb from Vandyke forum for help and codding.

' ----------------
' ----------------

' files required
Dim szIOSHostsFile
' Contain switch ip, one per line.
szIOSHostsFile = "C:\scripts\Healt-check\config-noradius\IOShosts.txt"
Dim szConfigFile
' Contain Login User, User Password and Enable Password, one per line.
szConfigFile = "C:\scripts\Healt-check\config-noradius\PasswordConfig.txt"
Dim szDumpConfFile
' write here any conf that you want to send.
szDumpConfFile = "C:\scripts\Healt-check\config-noradius\DumpConf.txt"
Dim szLogPath
' Path to log FOLDER
szLogPath = "C:\scripts\Healt-check\config-noradius\logs\"

' ----------------
' ----------------
' FileSystemObject
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
' User Name, User Pass
Dim LoginUserName 
Dim LoginUserPassword

Sub Main
  ' Complain if the files don't exist
  If ( Not fso.FileExists(szIOSHostsFile) ) Then
	MsgBox "FAILURE: IOS Hosts File does not exist: " & szIOSHostsFile
	Exit Sub
  End If
  If ( Not fso.FileExists(szConfigFile) ) Then
	MsgBox "FAILURE: Config File does not exist: " & szConfigFile
	Exit Sub
  End If
    If ( Not fso.FileExists(szDumpConfFile) ) Then
	MsgBox "FAILURE: DumpConfiguration File does not exist: " & szDumpConfFile
	Exit Sub
  End If
  ' Complain if log FOLDER don't exist
  If ( Not fso.FolderExists(szLogPath) ) Then
	MsgBox "FAILURE: Log Folder does not exist: " & szLogPath
	Exit Sub
  End If
  ' Get User Name, User Password from file
  Set fileConfigFile = fso.OpenTextFile(szConfigFile, 1)
  LoginUserName = fileConfigFile.ReadLine
  LoginUserPassword = fileConfigFile.ReadLine
  ' read switch ip from file
  Set fileIOSHosts = fso.OpenTextFile(szIOSHostsFile, 1)
  Do While fileIOSHosts.AtEndOfStream <> True
	szIOSHost = fileIOSHosts.ReadLine
	If ( len(szIOSHost) > 6 ) Then
		On Error Resume Next
		' ssh2 switch ip
		crt.session.connect("/SSH2" & szIOSHost)
		On Error Goto 0
			' if connection failed, stop the script and send a MsgBox to continue
		if not ( crt.session.connected ) then
			MsgBox szIOSHost & " Connection failed... Click OK to continue next switch. (Empty log created)"
			' create an empty log
			crt.Session.LogFileName = szLogPath & szIOSHost & "_Connection_failed_%D-%M-%Y_%hh%mm%ss.txt"
			crt.Session.Log True
			crt.Session.Log False
			' create a log file for each switch connection
			crt.Session.LogFileName = szLogPath & szIOSHost & "_%D-%M-%Y_%hh%mm%ss.txt"
			crt.Session.Log True
			' connect to switch
			call LoginME(LoginUserName, LoginUserPassword,)
				Set fileDumpConf = fso.OpenTextFile(szDumpConfFile, 1)
				' send configuration from file
				Do While fileDumpConf.AtEndOfStream <> True
					szDumpLine = fileDumpConf.ReadLine
					crt.Screen.Send (szDumpLine) & VbCr
			' stop logging
			crt.Session.Log False
			crt.Screen.Synchronous = False
		End If
	End If
  ' final Message Box with path to Log Folder
  MsgBox "Script execution finished, check log here: " & szLogPath
End Sub

' ---------------------------------------------------------
' Connect to switch, send User Name, User Pass
' ---------------------------------------------------------
Sub LoginMe (UsrName, PassWrd)
  crt.Screen.Synchronous = True
    crt.Screen.WaitForString "sername:"
  End If
  crt.Screen.Send UsrName & VbCr
  crt.Screen.WaitForString "assword:"
  crt.Screen.Send PassWrd & VbCr
  result = crt.screen.WaitForStrings("ME60",1)
	result = crt.screen.WaitForStrings("ME60",1)
  end if
End Sub
Reply With Quote
Old 01-28-2013, 09:03 AM
rtb rtb is offline
VanDyke Technical Support
Join Date: Aug 2008
Posts: 4,305
Hi francc,
1 script does evrything i need, but hangs on sending the username.
The second script i have found, does the login to the huawei devices, but notting more.
Can you tell me more about how this script that does everything you need is failing?

What line is indicated in the error message that you see when running the script?

If you just see a hang, what line is indicated when you cancel the running script?

What version of SecureCRT are you using?

VanDyke Software
Technical Support
Reply With Quote

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:19 AM.