merging 2 script for huawei equipment
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 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:
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. ' ---------------- ' SCRIPT SETTINGS: ' ---------------- ' 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\" ' ---------------- ' DON'T EDIT BELOW ' ---------------- ' 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 fileConfigFile.Close ' 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 else ' 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 loop ' stop logging crt.Session.Log False crt.Screen.Synchronous = False crt.session.Disconnect End If End If Loop fileIOSHosts.Close ' 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
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?
|Display Modes||Rate This Thread|