Tendo Posted May 4, 2023 Posted May 4, 2023 I am enhancing a script I found being used to add another ISP configuration on an interface (Basically have the ability to chose either A or B option to be configured on an interface). The GUI and options are selected fine but when trying to configure the selected options on to the interface the script fails. Can someone advise/point me to where I am missing anything... 'interface GigabitEthernet0/0/1'&@LF if $sInternetInstalled Then $input = $input&'undo shutdown'&@LF if $sISPChoosen = "ISP-A" Then ;run config code for ISP-A here Else ;run config code for ISP-B here EndIf EndIf Else $input = $input&'shutdown'&@LF EndIf '#'&@LF&'interface GigabitEthernet0/0/2'&@LF& _ ' shutdown'&@LF& _
Developers Jos Posted May 4, 2023 Developers Posted May 4, 2023 Your have 3 endif statements for only 2 If statements so you really need to get rid of the first endif in that snippet. SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
Tendo Posted May 4, 2023 Author Posted May 4, 2023 7 minutes ago, Jos said: Your have 3 endif statements for only 2 If statements so you really need to get rid of the first endif in that snippet. When I get rid of it, there is an error when I run the application Error: "if" statement has no matching "EndIf" statement.
Developers Jos Posted May 4, 2023 Developers Posted May 4, 2023 Is the posted code the full script? SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
mistersquirrle Posted May 4, 2023 Posted May 4, 2023 Then that means that what you've given us in the post isn't the 'complete' code. I would recommend that you run Tidy on your code: https://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/Tidy.html Generally in SciTE that means just pressing Ctrl + T. Then re-post your code with all of your Ifs properly, the first line of code in your first post is invalid syntax. I would also recommend that you add some logging, with ConsoleWrite so you can 'see' where the code is and what step its on. We ought not to misbehave, but we should look as though we could.
Tendo Posted May 4, 2023 Author Posted May 4, 2023 I have used tired to tidy it up here is the full code expandcollapse popup;Third batch of programming, ethernet ports configured $timeout=$hang $input = 'interface Ethernet0/0/0'&@LF& _ ' description M'&@LF& _ ' port link-type access'&@LF& _ ' port default vlan '&$sMVLAN&@LF& _ '#'&@LF& _ 'interface Ethernet0/0/7'&@LF& _ ' description W-2'&@LF& _ ' port link-type access'&@LF& _ ' port default vlan '&$sWVLAN&@LF& _ '#'&@LF _COMSendString($hComPort, $input&@LF) $readString = collectInput($hComPort,$timeout) if @error Then Return SetError(2,@ScriptLineNumber,"No input data in the given time period, contact IT @ " &$supportEmail&" for further assistance."&@CRLF&"Error: " & @error & @CRLF & "comPort: " & $iPort & @CRLF & "Timeout: " &$timeout) ;verify programming location $searchString="Ethernet0/0/7]" If StringinStr($readString,$searchString) == 0 THEN return SetError(6,@ScriptLineNumber,"Unable to login to verify programming, searching for string "&$searchString & ", contact IT @ " &$supportEmail&" for further assistance") ;Fourth batch of programming, Gigabit ports configured $timeout=$hang $input = 'interface GigabitEthernet0/0/0'&@LF& _ ' description Hybrid Port to LDA'&$sLDANumber&@LF& _ ' undo port hybrid vlan 1'&@LF& _ ' port hybrid tagged vlan 2 to 100'&@LF& _ ' combo-port fiber'&@LF& _ '#'&@LF& _ 'interface GigabitEthernet0/0/1'&@LF if $sInternetInstalled Then $input = $input&'undo shutdown'&@LF if $sISPChoosen = "ISP A" Then $input = $input&' description ISP A'&@LF& _ ' port link-type access'&@LF& _ ' port default vlan '&$sIVLAN&@LF& _ ' vlan dot1q-tunnel enable'&@LF& _ Else $input = $input&' description ISP B'&@LF& _ ' port link-type access'&@LF& _ ' port default vlan '&$sIVLAN2&@LF& _ ' vlan dot1q-tunnel enable'&@LF& _ EndIf EndIf Else $input = $input&'shutdown'&@LF EndIf '#'&@LF&'interface GigabitEthernet0/0/2'&@LF& _ ' shutdown'&@LF& _ '#'&@LF& _ 'interface GigabitEthernet0/0/3'&@LF& _ ' shutdown'&@LF& _ '#'&@LF& _ 'interface NULL0'&@LF& _ '#'&@LF _COMSendString($hComPort, $input&@LF) $readString = collectInput($hComPort,$timeout) if @error Then Return SetError(2,@ScriptLineNumber,"No input data in the given time period, contact IT @ " &$supportEmail&" for further assistance."&@CRLF&"Error: " & @error & @CRLF & "comPort: " & $iPort & @CRLF & "Timeout: " &$timeout) 1 hour ago, mistersquirrle said: Then that means that what you've given us in the post isn't the 'complete' code. I would recommend that you run Tidy on your code: https://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/Tidy.html Generally in SciTE that means just pressing Ctrl + T. Then re-post your code with all of your Ifs properly, the first line of code in your first post is invalid syntax. I would also recommend that you add some logging, with ConsoleWrite so you can 'see' where the code is and what step its on.
Nine Posted May 4, 2023 Posted May 4, 2023 (edited) The problem is that you have & _ at the very end on both $input = ... statements (inside if $sISPChoosen = "ISP A" Then). Just remove those on the last line and you'll be fine. ps. you also need to remove one endif like @Jos specified earlier. Edited May 4, 2023 by Nine “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
Werty Posted May 4, 2023 Posted May 4, 2023 _COMSendString($hComPort, $input&@LF) This also looks wrong. Some guy's script + some other guy's script = my script!
mistersquirrle Posted May 4, 2023 Posted May 4, 2023 There's a few issues, but we're closer to fixing it. You still haven't included everything relevant, but as Nine mentioned you have some line continuations that are incorrect, these lines: ' vlan dot1q-tunnel enable'&@LF& _ should be just ' vlan dot1q-tunnel enable' & @LF and then you have two EndIfs in a row when there should only be one: If $sInternetInstalled Then $input = $input & 'undo shutdown' & @LF If $sISPChoosen = "ISP A" Then $input = $input & ' description ISP A' & @LF & _ ' port link-type access' & @LF & _ ' port default vlan ' & $sIVLAN & @LF & _ ' vlan dot1q-tunnel enable' & @LF Else $input = $input & ' description ISP B' & @LF & _ ' port link-type access' & @LF & _ ' port default vlan ' & $sIVLAN2 & @LF & _ ' vlan dot1q-tunnel enable' & @LF ;EndIf ; Do not need this EndIf EndIf Else $input = $input & 'shutdown' & @LF EndIf then invalid syntax with this section, there should be some variable being assigned this string like "$input &= " before it: '#' & @LF & 'interface GigabitEthernet0/0/2' & @LF & _ ' shutdown' & @LF & _ '#' & @LF & _ 'interface GigabitEthernet0/0/3' & @LF & _ ' shutdown' & @LF & _ '#' & @LF & _ 'interface NULL0' & @LF & _ '#' & @LF Just so that I could run the Au3 SyntaxCheck Prod (Ctrl + F5) in SciTE I clean up the script a little bit: expandcollapse popupFunc _Test() Local $hang, $timeout, $input, $sMVLAN, $hComPort, $supportEmail, $iPort, $sLDANumber, $sWVLAN, $sInternetInstalled, $sISPChoosen, $sIVLAN, $sIVLAN2 ;Third batch of programming, ethernet ports configured\ $timeout = $hang $input = 'interface Ethernet0/0/0' & @LF & _ ' description M' & @LF & _ ' port link-type access' & @LF & _ ' port default vlan ' & $sMVLAN & @LF & _ '#' & @LF & _ 'interface Ethernet0/0/7' & @LF & _ ' description W-2' & @LF & _ ' port link-type access' & @LF & _ ' port default vlan ' & $sWVLAN & @LF & _ '#' & @LF _COMSendString($hComPort, $input & @LF) $readString = collectInput($hComPort, $timeout) If @error Then Return SetError(2, @ScriptLineNumber, "No input data in the given time period, contact IT @ " & $supportEmail & " for further assistance." & @CRLF & "Error: " & @error & @CRLF & "comPort: " & $iPort & @CRLF & "Timeout: " & $timeout) ;verify programming location $searchString = "Ethernet0/0/7]" If StringInStr($readString, $searchString) == 0 Then Return SetError(6, @ScriptLineNumber, "Unable to login to verify programming, searching for string " & $searchString & ", contact IT @ " & $supportEmail & " for further assistance") ;Fourth batch of programming, Gigabit ports configured $timeout = $hang $input = 'interface GigabitEthernet0/0/0' & @LF & _ ' description Hybrid Port to LDA' & $sLDANumber & @LF & _ ' undo port hybrid vlan 1' & @LF & _ ' port hybrid tagged vlan 2 to 100' & @LF & _ ' combo-port fiber' & @LF & _ '#' & @LF & _ 'interface GigabitEthernet0/0/1' & @LF If $sInternetInstalled Then $input = $input & 'undo shutdown' & @LF If $sISPChoosen = "ISP A" Then $input = $input & ' description ISP A' & @LF & _ ' port link-type access' & @LF & _ ' port default vlan ' & $sIVLAN & @LF & _ ' vlan dot1q-tunnel enable' & @LF Else $input = $input & ' description ISP B' & @LF & _ ' port link-type access' & @LF & _ ' port default vlan ' & $sIVLAN2 & @LF & _ ' vlan dot1q-tunnel enable' & @LF ;EndIf EndIf Else $input = $input & 'shutdown' & @LF EndIf ;~ '#' & @LF & 'interface GigabitEthernet0/0/2' & @LF & _ ;~ ' shutdown' & @LF & _ ;~ '#' & @LF & _ ;~ 'interface GigabitEthernet0/0/3' & @LF & _ ;~ ' shutdown' & @LF & _ ;~ '#' & @LF & _ ;~ 'interface NULL0' & @LF & _ ;~ '#' & @LF _COMSendString($hComPort, $input & @LF) $readString = collectInput($hComPort, $timeout) If @error Then Return SetError(2, @ScriptLineNumber, "No input data in the given time period, contact IT @ " & $supportEmail & " for further assistance." & @CRLF & "Error: " & @error & @CRLF & "comPort: " & $iPort & @CRLF & "Timeout: " & $timeout) EndFunc ;==>_Test Func _COMSendString($vVar1, $vVar2) EndFunc ;==>_COMSendString Func collectInput($vVar1, $vVar2) EndFunc ;==>collectInput This doesn't give any errors, however it will not run since I just created some dummy functions and all of the variables used/referenced have no values. Fix your errors and syntax and use the AutoIt/SciTE tools to check for errors. Ctrl + F5 to check for syntax errors, and Ctrl + T to tidy the code, which makes it easier to see indentations and things. We ought not to misbehave, but we should look as though we could.
Tendo Posted May 8, 2023 Author Posted May 8, 2023 I have been using ctrl + F5 as suggested and I have all errors cleared. However when I run the script I still get an Error in Expression. I suspect the error is coming from this section, does this look alright? 'interface GigabitEthernet0/0/1'&@LF if $sInternetInstalled Then $input = $input&'undo shutdown'&@LF if $sISPChoosen = "ISP A" Then $input = $input&' description ISP-A-QinQ'&@LF& _ ' port link-type access'&@LF& _ ' port default vlan '&$sIVLAN&@LF& _ ' vlan dot1q-tunnel enable'&@LF Else $input = $input&' description ISP-B-QinQ'&@LF& _ ' port link-type access'&@LF& _ ' port default vlan '&$sIVLAN2&@LF& _ ' vlan dot1q-tunnel enable'&@LF EndIf Else $input = $input&'shutdown'&@LF EndIf
mistersquirrle Posted May 8, 2023 Posted May 8, 2023 6 minutes ago, Tendo said: 'interface GigabitEthernet0/0/1'&@LF This is invalid syntax, you have just a string statement that's not attached to anything. Maybe you just missed some content when copy/paste, but other than that issue, there's no problem that I see with the small snippet. If $sInternetInstalled Then $input = $input & 'undo shutdown' & @LF If $sISPChoosen = "ISP A" Then $input = $input & ' description ISP-A-QinQ' & @LF & _ ' port link-type access' & @LF & _ ' port default vlan ' & $sIVLAN & @LF & _ ' vlan dot1q-tunnel enable' & @LF Else $input = $input & ' description ISP-B-QinQ' & @LF & _ ' port link-type access' & @LF & _ ' port default vlan ' & $sIVLAN2 & @LF & _ ' vlan dot1q-tunnel enable' & @LF EndIf Else $input = $input & 'shutdown' & @LF EndIf If you still can't figure it out, then I recommend that you post the full script and the actual error message that you receive. The error message should point you to where the problem is, usually it includes the line number. We ought not to misbehave, but we should look as though we could.
Tendo Posted May 10, 2023 Author Posted May 10, 2023 Apologies for the delay, here is the section of the script expandcollapse popuplogInfo("Preparing first batch of programming"&@CRLF) GUICtrlSetData($guiInfoLabel2,"Starting the first batch of programming.") ;First batch of programming, VLANs created $timeout=$hang $input = 'sys'&@LF& _ 'sysname '&$sAddress&@LF& _ ' header login information "Authorized Access only - Unauthorized users will be prosecuted"'&@LF& _ '#'&@LF& _ ' drop illegal-mac alarm'&@LF& _ '#'&@LF& _ 'vlan batch '&$sMVLAN&" "&$sWVLAN&" "&$sIVLAN&" "&$sFurnaceVLAN&" "&$sMgtVLAN&" "&$sIVLAN2&@LF& _ '#'&@LF& _ ' lldp enable'&@LF& _ '#'&@LF& _ 'ip vpn-instance 1'&@LF& _ '#'&@LF& _ 'vlan '&$sMVLAN&@LF& _ ' description Existing LDA'&$sLDANumber&' Meter Gateway'&@LF& _ ' name LDA'&$sLDANumber&'-Meters'&@LF& _ 'vlan '&$sWVLAN&@LF& _ ' description Existing LDA'&$sLDANumber&' Water Gateway'&@LF& _ ' name LDA'&$sLDANumber&'-Appliances'&@LF& _ 'vlan '&$sIVLAN&@LF& _ ' description Existing LDA'&$sLDANumber&' Isp-A Internet'&@LF& _ ' name LDA'&$sLDANumber&'-Isp-A-QinQ'&@LF& _ 'vlan '&$sFurnaceVLAN&@LF& _ ' description Existing LDA'&$sLDANumber&' Furnace Gateway'&@LF& _ ' name LDA'&$sLDANumber&'-Appliances-2'&@LF& _ 'vlan '&$sMgtVLAN&@LF& _ ' description for mgmt'&@LF& _ 'vlan '&$sIVLAN2&@LF& _ ' description Existing LDA'&$sLDANumber&' Isp-B Internet'&@LF& _ ' name LDA'&$sLDANumber&'-Isp-B-QinQ'&@LF& _ '#'&@LF _COMSendString($hComPort, $input&@LF) $readString = collectInput($hComPort,$timeout) if @error Then Return SetError(2,@ScriptLineNumber,"No input data in the given time period, contact IT @ " &$supportEmail&" for further assistance."&@CRLF&"Error: " & @error & @CRLF & "comPort: " & $iPort & @CRLF & "Timeout: " &$timeout) ;verify programming location $searchString="-vlan"&$sMgtVLAN&"]" If StringinStr($readString,$searchString) == 0 THEN return SetError(6,@ScriptLineNumber,"Unable to login to verify programming, searching for string "&$searchString & ", contact IT @ " &$supportEmail&" for further assistance") ;Second batch of programming, management configured $timeout=$hang $input = 'pki realm default'&@LF& _ '#'&@LF& _ 'ssl policy default_policy type server'&@LF& _ '#'&@LF& _ 'acl number 2099'&@LF& _ ' description ACL for Management'&@LF& _ ' rule 2 permit source 10.1.0.0 0.0.0.255'&@LF& _ ' rule 3 permit source 10.2.0.0 0.0.0.255'&@LF& _ ' rule 4 deny'&@LF& _ '#'&@LF& _ 'aaa'&@LF& _ ' authentication-scheme default'&@LF& _ ' authorization-scheme default'&@LF& _ ' accounting-scheme default'&@LF& _ ' domain default'&@LF& _ ' domain default_admin'&@LF& _ ' local-user administrator password irreversible-cipher %@%@s" xxx "%@%@'&@LF& _ ' local-user administrator privilege level 15'&@LF& _ ' local-user administrator service-type telnet terminal ssh http'&@LF& _ '#'&@LF& _ 'interface Vlanif'&$sMgtVLAN&@LF& _ ' ip address '&$sIP&' 255.255.255.0'&@LF& _ '#'&@LF _COMSendString($hComPort, $input&@LF) $readString = collectInput($hComPort,$timeout) if @error Then Return SetError(2,@ScriptLineNumber,"No input data in the given time period, contact IT @ " &$supportEmail&" for further assistance."&@CRLF&"Error: " & @error & @CRLF & "comPort: " & $iPort & @CRLF & "Timeout: " &$timeout) ;verify programming location $searchString="-Vlanif"&$sMgtVLAN&"]" If StringinStr($readString,$searchString) == 0 THEN return SetError(6,@ScriptLineNumber,"Unable to login to verify programming, searching for string "&$searchString & ", contact IT @ " &$supportEmail&" for further assistance") ;Third batch of programming, ethernet ports configured $timeout=$hang $input = 'interface Ethernet0/0/0'&@LF& _ ' description Meter'&@LF& _ ' port link-type access'&@LF& _ ' port default vlan '&$sMVLAN&@LF& _ '#'&@LF& _ 'interface Ethernet0/0/1'&@LF& _ ' description Water-Heater-1'&@LF& _ ' port link-type access'&@LF& _ ' port default vlan '&$sWVLAN&@LF& _ '#'&@LF& _ 'interface Ethernet0/0/2'&@LF& _ ' description Furnaces-1'&@LF& _ ' port link-type access'&@LF& _ ' port default vlan '&$sFurnaceVLAN&@LF& _ '#'&@LF& _ 'interface Ethernet0/0/3'&@LF& _ ' description Furnaces-2'&@LF& _ ' port link-type access'&@LF& _ ' port default vlan '&$sFurnaceVLAN&@LF& _ '#'&@LF& _ 'interface Ethernet0/0/4'&@LF& _ ' description Furnaces-3'&@LF& _ ' port link-type access'&@LF& _ ' port default vlan '&$sFurnaceVLAN&@LF& _ '#'&@LF& _ 'interface Ethernet0/0/5'&@LF& _ ' description Furnaces-4'&@LF& _ ' port link-type access'&@LF& _ ' port default vlan '&$sFurnaceVLAN&@LF& _ '#'&@LF& _ 'interface Ethernet0/0/6'&@LF& _ ' description Furnaces-5'&@LF& _ ' port link-type access'&@LF& _ ' port default vlan '&$sFurnaceVLAN&@LF& _ '#'&@LF& _ 'interface Ethernet0/0/7'&@LF& _ ' description Water-Heater-2'&@LF& _ ' port link-type access'&@LF& _ ' port default vlan '&$sWVLAN&@LF& _ '#'&@LF _COMSendString($hComPort, $input&@LF) $readString = collectInput($hComPort,$timeout) if @error Then Return SetError(2,@ScriptLineNumber,"No input data in the given time period, contact IT @ " &$supportEmail&" for further assistance."&@CRLF&"Error: " & @error & @CRLF & "comPort: " & $iPort & @CRLF & "Timeout: " &$timeout) ;verify programming location $searchString="Ethernet0/0/7]" If StringinStr($readString,$searchString) == 0 THEN return SetError(6,@ScriptLineNumber,"Unable to login to verify programming, searching for string "&$searchString & ", contact IT @ " &$supportEmail&" for further assistance") ;Fourth batch of programming, Gigabit ports configured $timeout=$hang $input = 'interface GigabitEthernet0/0/0'&@LF& _ ' description Hybrid Port to LDA'&$sLDANumber&@LF& _ ' undo port hybrid vlan 1'&@LF& _ ' port hybrid tagged vlan 2 to 4000'&@LF& _ ' combo-port fiber'&@LF& _ '#'&@LF& _ 'interface GigabitEthernet0/0/1'&@LF if $sInternetInstalled Then $input = $input&'undo shutdown'&@LF if $sISPChoosen = "Isp-A" Then $input = $input&' description Isp-A-QinQ'&@LF& _ ' port link-type access'&@LF& _ ' port default vlan '&$sIVLAN&@LF& _ ' vlan dot1q-tunnel enable'&@LF Else $input = $input&' description Isp-B-QinQ'&@LF& _ ' port link-type access'&@LF& _ ' port default vlan '&$sIVLAN2&@LF& _ ' vlan dot1q-tunnel enable'&@LF EndIf Else $input = $input&'shutdown'&@LF EndIf '#'&@LF& _ ;$input = $input&' description ISP'&@LF& _ ;' port link-type access'&@LF& _ ;' port default vlan '&$sInternetVLAN&@LF& _ '#'&@LF&'interface GigabitEthernet0/0/2'&@LF& _ ' shutdown'&@LF& _ '#'&@LF& _ 'interface GigabitEthernet0/0/3'&@LF& _ ' shutdown'&@LF& _ '#'&@LF& _ 'interface NULL0'&@LF& _ '#'&@LF _COMSendString($hComPort, $input&@LF) $readString = collectInput($hComPort,$timeout) if @error Then Return SetError(2,@ScriptLineNumber,"No input data in the given time period, contact IT @ " &$supportEmail&" for further assistance."&@CRLF&"Error: " & @error & @CRLF & "comPort: " & $iPort & @CRLF & "Timeout: " &$timeout) ;verify programming location $searchString="NULL0]" If StringinStr($readString,$searchString) == 0 THEN return SetError(6,@ScriptLineNumber,"Unable to login to verify programming, searching for string "&$searchString & ", contact IT @ " &$supportEmail&" for further assistance") Here is the error
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now