diff --git a/scripts/v6/ch10-04-bad-script.rsc b/scripts/v6/ch10-04-bad-script.rsc index 0b1b1a5..d9298e2 100644 --- a/scripts/v6/ch10-04-bad-script.rsc +++ b/scripts/v6/ch10-04-bad-script.rsc @@ -1,4 +1,4 @@ -:global Filename "ch10-04-bad-script.rsc" +:local Filename "ch10-04-bad-script.rsc" # A simple script to perform a series of tests on a # list of web sites. @@ -17,9 +17,10 @@ :global LogMessageFunc; # check arg type str of correct length passed - if (([:typeof $WebSiteName]!="str") or ([:len value=$WebSiteName] < 6)) do={ - $LogMessageFunc ("DnsResolveFunc: arg value $WebSiteName not a valid \ - string!"); + if (([:typeof $WebSiteName]!="str") or \ + ([:len value=$WebSiteName] < 6)) do={ + $LogMessageFunc ("DnsResolveFunc: arg value $WebSiteName not \ + a valid string!"); } return [/resolve $WebSiteName]; @@ -32,8 +33,8 @@ # check arg type ip is passed if ([:typeof $IpAddress] != "ip") do={ - $LogMessageFunc ("PingIpAddressFunc: arg value $IpAddress not an IP \ - address!"); + $LogMessageFunc ("PingIpAddressFunc: arg value $IpAddress not \ + an IP address!"); } return [/ping $IpAddress count=3]; @@ -45,13 +46,14 @@ :global LogMessageFunc; # check arg type str of correct length passed - if (([:typeof $SiteName] != "str") or ([:len value=$SiteName] < 6)) do={ - $LogMessageFunc ("GetWebPageFunc: arg value $SiteName not a valid \ - string!"); + if (([:typeof $SiteName] != "str") or \ + ([:len value=$SiteName] < 6)) do={ + $LogMessageFunc ("GetWebPageFunc: arg value $SiteName not a \ + valid string!"); } - return [/tool fetch url=("https://$SiteName") mode=https http-method=get \ - as-value keep-result=no]; + return [/tool fetch url=("https://$SiteName") mode=https \ + http-method=get as-value keep-result=no]; } ########## @@ -83,7 +85,6 @@ } # cleanup global namespace -:set Filename; :set LogMessageFunc; :set DnsResolveFunc; :set PingIpAddressFunc; diff --git a/scripts/v6/ch10-06-error_check.rsc b/scripts/v6/ch10-06-error_check.rsc index f554dc8..81de957 100644 --- a/scripts/v6/ch10-06-error_check.rsc +++ b/scripts/v6/ch10-06-error_check.rsc @@ -4,7 +4,7 @@ :do { :local SiteIpAddress [/resolve $SiteName]; :put "Site IP for $SiteName is $SiteIpAddress"; - } on-error { + } on-error={ :put "Name lookup failed for $SiteName" } } \ No newline at end of file diff --git a/scripts/v6/ch10-07-bad-script.rsc b/scripts/v6/ch10-07-bad-script.rsc index 053f6d4..b171dd9 100644 --- a/scripts/v6/ch10-07-bad-script.rsc +++ b/scripts/v6/ch10-07-bad-script.rsc @@ -1,4 +1,4 @@ -:global Filename "ch10-07-bad-script.rsc" +:local Filename "ch10-07-bad-script.rsc" # A script to perform a series of tests on a # list of web sites. @@ -19,8 +19,8 @@ # check arg type str of correct length passed :if (([:typeof $WebSiteName] != "str") or \ ([:len value=$WebSiteName] < 6)) do={ - $LogMessageFunc ("DnsResolveFunc: arg value $WebSiteName not a valid \ - string!"); + $LogMessageFunc ("DnsResolveFunc: arg value $WebSiteName not \ + a valid string!"); :return "*** test failed ***"; } @@ -29,8 +29,8 @@ :do { return [/resolve $WebSiteName]; } on-error={ - $LogMessageFunc ("DnsResolveFunc: name resolution failed for site: \ - $WebSiteName!"); + $LogMessageFunc ("DnsResolveFunc: name resolution failed for \ + site: $WebSiteName!"); :return "*** test failed ***"; } } @@ -42,16 +42,17 @@ # check arg type ip is passed :if ([:typeof $IpAddress] != "ip") do={ - $LogMessageFunc ("PingIpAddressFunc: arg value $IpAddress not an \ - IP address!"); + $LogMessageFunc ("PingIpAddressFunc: arg value $IpAddress not \ + an IP address!"); :return "*** test failed ***"; } # try a ping :do { return [/ping $IpAddress count=3]; - } on-error { - $LogMessageFunc ("PingIpAddressFunc: ping test failed: $IpAddress !"); + } on-error={ + $LogMessageFunc ("PingIpAddressFunc: ping test failed: \ + $IpAddress !"); :return "*** test failed ***"; } } @@ -62,9 +63,10 @@ :global LogMessageFunc; # check arg type str of correct length passed - :if (([:typeof $SiteName] != "str") or ([:len value=$SiteName] < 6)) do={ - $LogMessageFunc ("GetWebPageFunc: arg value $SiteName not a valid \ - string!"); + :if (([:typeof $SiteName] != "str") or \ + ([:len value=$SiteName] < 6)) do={ + $LogMessageFunc ("GetWebPageFunc: arg value $SiteName not a \ + valid string!"); :return "*** test failed ***"; } @@ -72,7 +74,7 @@ :do { :return [/tool fetch url=("https://$SiteName") mode=https \ http-method=get as-value keep-result=no]; - } on-error { + } on-error={ $LogMessageFunc ("GetWebPageFunc: unable to retrieve site: \ $SiteName !"); :return { "duration"="*** test failed ***" } @@ -108,7 +110,6 @@ } # cleanup global namespace -:set Filename; :set LogMessageFunc; :set DnsResolveFunc; :set PingIpAddressFunc; diff --git a/scripts/v6/ch10-08-bad-script.rsc b/scripts/v6/ch10-08-bad-script.rsc index 7b1f619..267f6ab 100644 --- a/scripts/v6/ch10-08-bad-script.rsc +++ b/scripts/v6/ch10-08-bad-script.rsc @@ -1,4 +1,4 @@ -:global Filename "ch10-08-bad-script.rsc" +:local Filename "ch10-08-bad-script.rsc" # A script to perform a series of tests on a # list of web sites. @@ -9,7 +9,7 @@ # debug function :global DebugFunc do={ :global DEBUG; - :if ($DEBUG) do={ :put "**Debug: $1"; } + :if ($DEBUG) do={ :put "**Debug: $1"; } } # function to log error messages @@ -35,8 +35,8 @@ :if (([:typeof $WebSiteName] != "str") or \ ([:len value=$WebSiteName] < 6)) do={ - :local ErrorMsg "DnsResolveFunc: arg value $WebSiteName not a valid \ - string!"; + :local ErrorMsg "DnsResolveFunc: arg value $WebSiteName \ + not a valid string!"; $LogMessageFunc $ErrorMsg; $DebugFunc $ErrorMsg; :return "*** test failed ***"; @@ -51,8 +51,8 @@ :return $SiteIpAddr; } on-error={ $DebugFunc "DNS lookup failed!"; - $LogMessageFunc ("DnsResolveFunc: name resolution failed for site: \ - $WebSiteName!"); + $LogMessageFunc ("DnsResolveFunc: name resolution failed for \ + site: $WebSiteName!"); :return "*** test failed ***"; } } @@ -64,16 +64,16 @@ # check arg type ip is passed :if ([:typeof $IpAddress] != "ip") do={ - $LogMessageFunc ("PingIpAddressFunc: arg value $IpAddress not an IP \ - address!"); + $LogMessageFunc ("PingIpAddressFunc: arg value $IpAddress not \ + an IP address!"); :return "*** test failed ***"; } :do { return [/ping $IpAddress count=3]; } on-error { - $LogMessageFunc ("PingIpAddressFunc: ping test to IP address failed: \ - $IpAddress !"); + $LogMessageFunc ("PingIpAddressFunc: ping test to IP address \ + failed: $IpAddress !"); :return "*** test failed ***"; } } @@ -84,17 +84,19 @@ :global LogMessageFunc; # check arg type str of correct length passed - if (([:typeof $SiteName] != "str") or ([:len value=$SiteName] < 6)) do={ - $LogMessageFunc ("GetWebPageFunc: arg value $SiteName not a valid \ - string!"); + if (([:typeof $SiteName] != "str") or \ + ([:len value=$SiteName] < 6)) do={ + $LogMessageFunc ("GetWebPageFunc: arg value $SiteName not a \ + valid string!"); :return { "duration"="*** test failed ***" }; } do { - return [/tool fetch url=("https://$SiteName") mode=https http-method=get \ - as-value keep-result=no]; + return [/tool fetch url=("https://$SiteName") mode=https \ + http-method=get as-value keep-result=no]; } on-error { - $LogMessageFunc ("GetWebPageFunc: unable to retrieve site: $SiteName !"); + $LogMessageFunc ("GetWebPageFunc: unable to retrieve site: \ + $SiteName !"); return { "duration"="*** test failed ***" }; } } @@ -128,7 +130,6 @@ } # cleanup global namespace -:set Filename; :set LogMessageFunc; :set DnsResolveFunc; :set PingIpAddressFunc; diff --git a/scripts/v6/ch10-10-add-remove-vlans.rsc b/scripts/v6/ch10-10-add-remove-vlans.rsc index 84fd36d..c5d877f 100644 --- a/scripts/v6/ch10-10-add-remove-vlans.rsc +++ b/scripts/v6/ch10-10-add-remove-vlans.rsc @@ -1,9 +1,9 @@ # ch10-10-add-remove-vlans.rsc -# a script to add and remove 50 VLANs to/from +# a script to add and remove 50 VLANs to/fromon-error={ # a Mikrotik router interface -: for VlanId from 200 to 249 do={ +:for VlanId from 200 to 249 do={ # find LAN interface ID :local LanInterface "ether2"; @@ -15,7 +15,7 @@ interface=$LanInterfaceId; } -: for VlanId from 200 to 249 do={ +:for VlanId from 200 to 249 do={ # find LAN interface ID :local LanInterface "ether2"; diff --git a/scripts/v6/ch10-11-add-remove-vlans.rsc b/scripts/v6/ch10-11-add-remove-vlans.rsc index 13b9888..49d912a 100644 --- a/scripts/v6/ch10-11-add-remove-vlans.rsc +++ b/scripts/v6/ch10-11-add-remove-vlans.rsc @@ -7,7 +7,7 @@ :local LanInterface "ether2"; :local LanInterfaceId [/interface find default-name=$LanInterface]; -: for VlanId from 200 to 249 do={ +:for VlanId from 200 to 249 do={ # add VLAN to LAN interface :local VlanName "VLAN$VlanId"; @@ -15,7 +15,7 @@ interface=$LanInterfaceId; } -: for VlanId from 200 to 249 do={ +:for VlanId from 200 to 249 do={ # add VLAN to LAN interface :local VlanName "VLAN$VlanId"; diff --git a/scripts/v6/ch10-12-add-remove-vlans.rsc b/scripts/v6/ch10-12-add-remove-vlans.rsc index e2e27da..ffa3ce0 100644 --- a/scripts/v6/ch10-12-add-remove-vlans.rsc +++ b/scripts/v6/ch10-12-add-remove-vlans.rsc @@ -8,7 +8,7 @@ :local LanInterfaceId [/interface find default-name=$LanInterface]; :local AddLoopTime [:time { - : for VlanId from 200 to 249 do={ + :for VlanId from 200 to 249 do={ # add VLAN to LAN interface :local VlanName "VLAN$VlanId"; @@ -20,7 +20,7 @@ :put "Add loop time: $AddLoopTime"; :local RemoveLoopTime [:time { - : for VlanId from 200 to 249 do={ + :for VlanId from 200 to 249 do={ # add VLAN to LAN interface :local VlanName "VLAN$VlanId"; diff --git a/scripts/v6/ch5-05-indentation.rsc b/scripts/v6/ch5-05-indentation.rsc index cd25b32..ff22931 100644 --- a/scripts/v6/ch5-05-indentation.rsc +++ b/scripts/v6/ch5-05-indentation.rsc @@ -1,6 +1,6 @@ # ch5-05-indentation.rsc -# Create an if-else statement with no additional indentation +# Create an if-else statement with indentation :local DayOfWeek "Monday"; if ($DayOfWeek = "Monday") do={ diff --git a/scripts/v6/ch6-08-local-vars.rsc b/scripts/v6/ch6-08-local-vars.rsc index a391289..8fef7b4 100644 --- a/scripts/v6/ch6-08-local-vars.rsc +++ b/scripts/v6/ch6-08-local-vars.rsc @@ -7,13 +7,13 @@ :put ("Variable contents: $SmallNumber"); # Assign some data to the variable -:set SmallNumber 2 +:set SmallNumber 2; # Print its value again :put ("Variable contents: $SmallNumber"); # Let's change the variable value -:set SmallNumber 3 +:set SmallNumber 3; # Print its value again :put ("Variable contents: $SmallNumber"); \ No newline at end of file diff --git a/scripts/v6/ch6-12-global-vars3.rsc b/scripts/v6/ch6-12-global-vars3.rsc index a6d476d..a1c6838 100644 --- a/scripts/v6/ch6-12-global-vars3.rsc +++ b/scripts/v6/ch6-12-global-vars3.rsc @@ -15,7 +15,8 @@ if ( [:typeof $WanInterfaces] = "nothing") do={ # Is the variable an array data type? if ( [:typeof $WanInterfaces] != "array") do={ - :error "The WanInterfaces global variable is not an array data type. Exiting." + :error "The WanInterfaces global variable is not an array data \ + type. Exiting." } # Let's step through the interfaces in the array diff --git a/scripts/v6/ch7-02-basic-if.rsc b/scripts/v6/ch7-02-basic-if.rsc index ffc1364..e72d571 100644 --- a/scripts/v6/ch7-02-basic-if.rsc +++ b/scripts/v6/ch7-02-basic-if.rsc @@ -24,6 +24,6 @@ if ( $WanPingCount = 0) do={ } if ( ($WanPingCount < $PingCount) and ($WanPingCount > 0) ) do={ - :log warning "The Internet connection may be degraded. (Ping result: \ - $WanPingCount/$PingCount)"; + :log warning "The Internet connection may be degraded. (Ping \ + result: $WanPingCount/$PingCount)"; } diff --git a/scripts/v6/ch7-06-if-multiple-conditions.rsc b/scripts/v6/ch7-06-if-multiple-conditions.rsc index 2108ed5..9722d04 100644 --- a/scripts/v6/ch7-06-if-multiple-conditions.rsc +++ b/scripts/v6/ch7-06-if-multiple-conditions.rsc @@ -5,7 +5,7 @@ :put "The current time is : $CurrentTime"; # declare the time of day variable -:local TimeOfDay +:local TimeOfDay; # Check if it's very early :if (($CurrentTime >= 00:00) and ($CurrentTime < 06:00)) do={ diff --git a/scripts/v6/ch7-07-nested-if-statements.rsc b/scripts/v6/ch7-07-nested-if-statements.rsc index 78ab5ca..b060e96 100644 --- a/scripts/v6/ch7-07-nested-if-statements.rsc +++ b/scripts/v6/ch7-07-nested-if-statements.rsc @@ -5,7 +5,7 @@ :put "The current time is : $CurrentTime"; # declare the time of day variable -:local TimeOfDay +:local TimeOfDay; # Check if it's before noon :if ($CurrentTime < 12:00) do={ @@ -13,7 +13,8 @@ # it's before noon, let's see what time of the morning # it is using a nested if-else statement if ($CurrentTime < 06:00) do={ - :set TimeOfDay "It's very early in the morning...shouldn't you be in bed?"; + :set TimeOfDay "It's very early in the morning...shouldn't \ + you be in bed?"; } else={ # it must be between 06:01 and 11:59 to reach here :set TimeOfDay "Good morning!"; diff --git a/scripts/v6/ch7-08-if-else-binary.rsc b/scripts/v6/ch7-08-if-else-binary.rsc index 06b679a..1200784 100644 --- a/scripts/v6/ch7-08-if-else-binary.rsc +++ b/scripts/v6/ch7-08-if-else-binary.rsc @@ -3,12 +3,12 @@ # define WAN interface name :local WanInterfaceName "ether1-WAN"; -# find the interface index -:local InterfaceIndex [/interface ethernet find name=$WanInterfaceName]; +# find the interface ID +:local InterfaceId [/interface ethernet find name=$WanInterfaceName]; :local UpDown; -if ([:interface ethernet get $InterfaceIndex]->"running") do={ +if ([:interface ethernet get $InterfaceId]->"running") do={ :set UpDown "up"; } else={ :set UpDown "down"; diff --git a/scripts/v6/ch7-09-if-binary-simplified.rsc b/scripts/v6/ch7-09-if-binary-simplified.rsc index 3c7aba4..3a04bc1 100644 --- a/scripts/v6/ch7-09-if-binary-simplified.rsc +++ b/scripts/v6/ch7-09-if-binary-simplified.rsc @@ -4,10 +4,10 @@ :local WanInterfaceName "ether1-WAN"; # find the interface index -:local InterfaceIndex [/interface ethernet find name=$WanInterfaceName]; +:local InterfaceId [/interface ethernet find name=$WanInterfaceName]; :local UpDown "down"; -if ([:interface ethernet get $InterfaceIndex]->"running") do={ +if ([:interface ethernet get $InterfaceId]->"running") do={ :set UpDown "up" } diff --git a/scripts/v6/ch8-01-for-basic.rsc b/scripts/v6/ch8-01-for-basic.rsc index cd1b173..5a4a508 100644 --- a/scripts/v6/ch8-01-for-basic.rsc +++ b/scripts/v6/ch8-01-for-basic.rsc @@ -4,7 +4,7 @@ # the 12 times table :for LoopCount from=1 to=5 do={ - :put ("Current loop counter is: $LoopCount"); + :put "Current loop counter is: $LoopCount"; :put ("12 x $LoopCount is: " . (12 * $LoopCount)); } diff --git a/scripts/v6/ch8-02-for-check-web.rsc b/scripts/v6/ch8-02-for-check-web.rsc index 54584ad..1b65b21 100644 --- a/scripts/v6/ch8-02-for-check-web.rsc +++ b/scripts/v6/ch8-02-for-check-web.rsc @@ -12,9 +12,8 @@ :local PingResult [/ping $Site count=3 ]; :if ($PingResult > 0) do { - :put ("\nWeb site $Site reached OK\n"); + :put "\nWeb site $Site reached OK\n"; } else={ - :put ("\nNo response from web site: $Site\n"); + :put "\nNo response from web site: $Site\n"; } -} - +} \ No newline at end of file diff --git a/scripts/v6/ch8-03-for-create-vlan.rsc b/scripts/v6/ch8-03-for-create-vlan.rsc index ae1af48..09cedf1 100644 --- a/scripts/v6/ch8-03-for-create-vlan.rsc +++ b/scripts/v6/ch8-03-for-create-vlan.rsc @@ -8,8 +8,8 @@ :for VlanId from=100 to=150 step=10 do={ :put ("Creating VLAN $VlanId on interface $InterfaceName"); - :local VlanName ("vlan" . $VlanId); - /interface vlan add name=$VlanName vlan-id=$VlanId interface=$InterfaceName; + /interface vlan add name=$VlanName vlan-id=$VlanId \ + interface=$InterfaceName; } diff --git a/scripts/v6/ch9-03-mutiple-args-array.rsc b/scripts/v6/ch9-03-mutiple-args-array.rsc index d0a91aa..182e600 100644 --- a/scripts/v6/ch9-03-mutiple-args-array.rsc +++ b/scripts/v6/ch9-03-mutiple-args-array.rsc @@ -28,12 +28,14 @@ } # data type checks passed, print the interface data - :put "$InterfaceName: IP address = $InterfaceIp, speed = $InterfaceSpeed"; + :put "$InterfaceName: IP address = $InterfaceIp, speed = \ + $InterfaceSpeed"; } # --- end of function --- # Let's call the function with some sample values in an array -:local Args { ifname="WAN1"; ifspeed="100Mbps"; ifip="192.168.99.1/24" }; +:local Args { ifname="WAN1"; ifspeed="100Mbps"; + ifip="192.168.99.1/24" }; $PrintInterfaceAttrsFunc $Args; # Let's call the function with some other values in an array diff --git a/scripts/v6/ch9-06-str-funcs-mod.rsc b/scripts/v6/ch9-06-str-funcs-mod.rsc index 36d424e..76a7b51 100644 --- a/scripts/v6/ch9-06-str-funcs-mod.rsc +++ b/scripts/v6/ch9-06-str-funcs-mod.rsc @@ -16,7 +16,7 @@ # function to remove last char from a string # -# e.g. :local ChoppedVar [$chopStrFunc "string with extra char,"] +# e.g. :local ChoppedVar [$ChopStrFunc "string with extra char,"] # :global ChopStrFunc do={ :return [ :pick $1 0 ( [ :len $1 ] -1 ) ]; diff --git a/scripts/v6/ch9-07-use-str-module.rsc b/scripts/v6/ch9-07-use-str-module.rsc index 00b230d..3664321 100644 --- a/scripts/v6/ch9-07-use-str-module.rsc +++ b/scripts/v6/ch9-07-use-str-module.rsc @@ -1,6 +1,7 @@ # filename: ch9-07-use-str-module.rsc -# import the functions we need and declare the function names we wish to use +# import the functions we need and declare the function +# names we wish to use /import "ch9-06-str-funcs-mod.rsc" :global RemoveSpaceFunc; :global ChopStrFunc; diff --git a/scripts/v7/ch10-04-bad-script.rsc b/scripts/v7/ch10-04-bad-script.rsc index 0b1b1a5..d9298e2 100644 --- a/scripts/v7/ch10-04-bad-script.rsc +++ b/scripts/v7/ch10-04-bad-script.rsc @@ -1,4 +1,4 @@ -:global Filename "ch10-04-bad-script.rsc" +:local Filename "ch10-04-bad-script.rsc" # A simple script to perform a series of tests on a # list of web sites. @@ -17,9 +17,10 @@ :global LogMessageFunc; # check arg type str of correct length passed - if (([:typeof $WebSiteName]!="str") or ([:len value=$WebSiteName] < 6)) do={ - $LogMessageFunc ("DnsResolveFunc: arg value $WebSiteName not a valid \ - string!"); + if (([:typeof $WebSiteName]!="str") or \ + ([:len value=$WebSiteName] < 6)) do={ + $LogMessageFunc ("DnsResolveFunc: arg value $WebSiteName not \ + a valid string!"); } return [/resolve $WebSiteName]; @@ -32,8 +33,8 @@ # check arg type ip is passed if ([:typeof $IpAddress] != "ip") do={ - $LogMessageFunc ("PingIpAddressFunc: arg value $IpAddress not an IP \ - address!"); + $LogMessageFunc ("PingIpAddressFunc: arg value $IpAddress not \ + an IP address!"); } return [/ping $IpAddress count=3]; @@ -45,13 +46,14 @@ :global LogMessageFunc; # check arg type str of correct length passed - if (([:typeof $SiteName] != "str") or ([:len value=$SiteName] < 6)) do={ - $LogMessageFunc ("GetWebPageFunc: arg value $SiteName not a valid \ - string!"); + if (([:typeof $SiteName] != "str") or \ + ([:len value=$SiteName] < 6)) do={ + $LogMessageFunc ("GetWebPageFunc: arg value $SiteName not a \ + valid string!"); } - return [/tool fetch url=("https://$SiteName") mode=https http-method=get \ - as-value keep-result=no]; + return [/tool fetch url=("https://$SiteName") mode=https \ + http-method=get as-value keep-result=no]; } ########## @@ -83,7 +85,6 @@ } # cleanup global namespace -:set Filename; :set LogMessageFunc; :set DnsResolveFunc; :set PingIpAddressFunc; diff --git a/scripts/v7/ch10-06-error_check.rsc b/scripts/v7/ch10-06-error_check.rsc index f554dc8..81de957 100644 --- a/scripts/v7/ch10-06-error_check.rsc +++ b/scripts/v7/ch10-06-error_check.rsc @@ -4,7 +4,7 @@ :do { :local SiteIpAddress [/resolve $SiteName]; :put "Site IP for $SiteName is $SiteIpAddress"; - } on-error { + } on-error={ :put "Name lookup failed for $SiteName" } } \ No newline at end of file diff --git a/scripts/v7/ch10-07-bad-script.rsc b/scripts/v7/ch10-07-bad-script.rsc index 053f6d4..b171dd9 100644 --- a/scripts/v7/ch10-07-bad-script.rsc +++ b/scripts/v7/ch10-07-bad-script.rsc @@ -1,4 +1,4 @@ -:global Filename "ch10-07-bad-script.rsc" +:local Filename "ch10-07-bad-script.rsc" # A script to perform a series of tests on a # list of web sites. @@ -19,8 +19,8 @@ # check arg type str of correct length passed :if (([:typeof $WebSiteName] != "str") or \ ([:len value=$WebSiteName] < 6)) do={ - $LogMessageFunc ("DnsResolveFunc: arg value $WebSiteName not a valid \ - string!"); + $LogMessageFunc ("DnsResolveFunc: arg value $WebSiteName not \ + a valid string!"); :return "*** test failed ***"; } @@ -29,8 +29,8 @@ :do { return [/resolve $WebSiteName]; } on-error={ - $LogMessageFunc ("DnsResolveFunc: name resolution failed for site: \ - $WebSiteName!"); + $LogMessageFunc ("DnsResolveFunc: name resolution failed for \ + site: $WebSiteName!"); :return "*** test failed ***"; } } @@ -42,16 +42,17 @@ # check arg type ip is passed :if ([:typeof $IpAddress] != "ip") do={ - $LogMessageFunc ("PingIpAddressFunc: arg value $IpAddress not an \ - IP address!"); + $LogMessageFunc ("PingIpAddressFunc: arg value $IpAddress not \ + an IP address!"); :return "*** test failed ***"; } # try a ping :do { return [/ping $IpAddress count=3]; - } on-error { - $LogMessageFunc ("PingIpAddressFunc: ping test failed: $IpAddress !"); + } on-error={ + $LogMessageFunc ("PingIpAddressFunc: ping test failed: \ + $IpAddress !"); :return "*** test failed ***"; } } @@ -62,9 +63,10 @@ :global LogMessageFunc; # check arg type str of correct length passed - :if (([:typeof $SiteName] != "str") or ([:len value=$SiteName] < 6)) do={ - $LogMessageFunc ("GetWebPageFunc: arg value $SiteName not a valid \ - string!"); + :if (([:typeof $SiteName] != "str") or \ + ([:len value=$SiteName] < 6)) do={ + $LogMessageFunc ("GetWebPageFunc: arg value $SiteName not a \ + valid string!"); :return "*** test failed ***"; } @@ -72,7 +74,7 @@ :do { :return [/tool fetch url=("https://$SiteName") mode=https \ http-method=get as-value keep-result=no]; - } on-error { + } on-error={ $LogMessageFunc ("GetWebPageFunc: unable to retrieve site: \ $SiteName !"); :return { "duration"="*** test failed ***" } @@ -108,7 +110,6 @@ } # cleanup global namespace -:set Filename; :set LogMessageFunc; :set DnsResolveFunc; :set PingIpAddressFunc; diff --git a/scripts/v7/ch10-08-bad-script.rsc b/scripts/v7/ch10-08-bad-script.rsc index 7b1f619..267f6ab 100644 --- a/scripts/v7/ch10-08-bad-script.rsc +++ b/scripts/v7/ch10-08-bad-script.rsc @@ -1,4 +1,4 @@ -:global Filename "ch10-08-bad-script.rsc" +:local Filename "ch10-08-bad-script.rsc" # A script to perform a series of tests on a # list of web sites. @@ -9,7 +9,7 @@ # debug function :global DebugFunc do={ :global DEBUG; - :if ($DEBUG) do={ :put "**Debug: $1"; } + :if ($DEBUG) do={ :put "**Debug: $1"; } } # function to log error messages @@ -35,8 +35,8 @@ :if (([:typeof $WebSiteName] != "str") or \ ([:len value=$WebSiteName] < 6)) do={ - :local ErrorMsg "DnsResolveFunc: arg value $WebSiteName not a valid \ - string!"; + :local ErrorMsg "DnsResolveFunc: arg value $WebSiteName \ + not a valid string!"; $LogMessageFunc $ErrorMsg; $DebugFunc $ErrorMsg; :return "*** test failed ***"; @@ -51,8 +51,8 @@ :return $SiteIpAddr; } on-error={ $DebugFunc "DNS lookup failed!"; - $LogMessageFunc ("DnsResolveFunc: name resolution failed for site: \ - $WebSiteName!"); + $LogMessageFunc ("DnsResolveFunc: name resolution failed for \ + site: $WebSiteName!"); :return "*** test failed ***"; } } @@ -64,16 +64,16 @@ # check arg type ip is passed :if ([:typeof $IpAddress] != "ip") do={ - $LogMessageFunc ("PingIpAddressFunc: arg value $IpAddress not an IP \ - address!"); + $LogMessageFunc ("PingIpAddressFunc: arg value $IpAddress not \ + an IP address!"); :return "*** test failed ***"; } :do { return [/ping $IpAddress count=3]; } on-error { - $LogMessageFunc ("PingIpAddressFunc: ping test to IP address failed: \ - $IpAddress !"); + $LogMessageFunc ("PingIpAddressFunc: ping test to IP address \ + failed: $IpAddress !"); :return "*** test failed ***"; } } @@ -84,17 +84,19 @@ :global LogMessageFunc; # check arg type str of correct length passed - if (([:typeof $SiteName] != "str") or ([:len value=$SiteName] < 6)) do={ - $LogMessageFunc ("GetWebPageFunc: arg value $SiteName not a valid \ - string!"); + if (([:typeof $SiteName] != "str") or \ + ([:len value=$SiteName] < 6)) do={ + $LogMessageFunc ("GetWebPageFunc: arg value $SiteName not a \ + valid string!"); :return { "duration"="*** test failed ***" }; } do { - return [/tool fetch url=("https://$SiteName") mode=https http-method=get \ - as-value keep-result=no]; + return [/tool fetch url=("https://$SiteName") mode=https \ + http-method=get as-value keep-result=no]; } on-error { - $LogMessageFunc ("GetWebPageFunc: unable to retrieve site: $SiteName !"); + $LogMessageFunc ("GetWebPageFunc: unable to retrieve site: \ + $SiteName !"); return { "duration"="*** test failed ***" }; } } @@ -128,7 +130,6 @@ } # cleanup global namespace -:set Filename; :set LogMessageFunc; :set DnsResolveFunc; :set PingIpAddressFunc; diff --git a/scripts/v7/ch10-10-add-remove-vlans.rsc b/scripts/v7/ch10-10-add-remove-vlans.rsc index e9b6455..390cffd 100644 --- a/scripts/v7/ch10-10-add-remove-vlans.rsc +++ b/scripts/v7/ch10-10-add-remove-vlans.rsc @@ -3,7 +3,7 @@ # a script to add and remove 50 VLANs to/from # a Mikrotik router interface -: for VlanId from 200 to 249 do={ +:for VlanId from 200 to 249 do={ # find LAN interface ID :local LanInterface "ether2"; @@ -15,7 +15,7 @@ interface=$LanInterfaceId; } -: for VlanId from 200 to 249 do={ +:for VlanId from 200 to 249 do={ # find LAN interface ID :local LanInterface "ether2"; diff --git a/scripts/v7/ch10-11-add-remove-vlans.rsc b/scripts/v7/ch10-11-add-remove-vlans.rsc index 13b9888..49d912a 100644 --- a/scripts/v7/ch10-11-add-remove-vlans.rsc +++ b/scripts/v7/ch10-11-add-remove-vlans.rsc @@ -7,7 +7,7 @@ :local LanInterface "ether2"; :local LanInterfaceId [/interface find default-name=$LanInterface]; -: for VlanId from 200 to 249 do={ +:for VlanId from 200 to 249 do={ # add VLAN to LAN interface :local VlanName "VLAN$VlanId"; @@ -15,7 +15,7 @@ interface=$LanInterfaceId; } -: for VlanId from 200 to 249 do={ +:for VlanId from 200 to 249 do={ # add VLAN to LAN interface :local VlanName "VLAN$VlanId"; diff --git a/scripts/v7/ch10-12-add-remove-vlans.rsc b/scripts/v7/ch10-12-add-remove-vlans.rsc index e2e27da..ffa3ce0 100644 --- a/scripts/v7/ch10-12-add-remove-vlans.rsc +++ b/scripts/v7/ch10-12-add-remove-vlans.rsc @@ -8,7 +8,7 @@ :local LanInterfaceId [/interface find default-name=$LanInterface]; :local AddLoopTime [:time { - : for VlanId from 200 to 249 do={ + :for VlanId from 200 to 249 do={ # add VLAN to LAN interface :local VlanName "VLAN$VlanId"; @@ -20,7 +20,7 @@ :put "Add loop time: $AddLoopTime"; :local RemoveLoopTime [:time { - : for VlanId from 200 to 249 do={ + :for VlanId from 200 to 249 do={ # add VLAN to LAN interface :local VlanName "VLAN$VlanId"; diff --git a/scripts/v7/ch6-08-local-vars.rsc b/scripts/v7/ch6-08-local-vars.rsc index a391289..8fef7b4 100644 --- a/scripts/v7/ch6-08-local-vars.rsc +++ b/scripts/v7/ch6-08-local-vars.rsc @@ -7,13 +7,13 @@ :put ("Variable contents: $SmallNumber"); # Assign some data to the variable -:set SmallNumber 2 +:set SmallNumber 2; # Print its value again :put ("Variable contents: $SmallNumber"); # Let's change the variable value -:set SmallNumber 3 +:set SmallNumber 3; # Print its value again :put ("Variable contents: $SmallNumber"); \ No newline at end of file diff --git a/scripts/v7/ch6-12-global-vars3.rsc b/scripts/v7/ch6-12-global-vars3.rsc index eccafd8..311c3b7 100644 --- a/scripts/v7/ch6-12-global-vars3.rsc +++ b/scripts/v7/ch6-12-global-vars3.rsc @@ -15,7 +15,8 @@ if ( [:typeof $WanInterfaces] = "nothing") do={ # Is the variable an array data type? if ( [:typeof $WanInterfaces] != "array") do={ - :error "The WanInterfaces global variable is not an array data type. Exiting." + :error "The WanInterfaces global variable is not an array data \ + type. Exiting." } # Let's step through the interfaces in the array diff --git a/scripts/v7/ch7-02-basic-if.rsc b/scripts/v7/ch7-02-basic-if.rsc index ffc1364..e72d571 100644 --- a/scripts/v7/ch7-02-basic-if.rsc +++ b/scripts/v7/ch7-02-basic-if.rsc @@ -24,6 +24,6 @@ if ( $WanPingCount = 0) do={ } if ( ($WanPingCount < $PingCount) and ($WanPingCount > 0) ) do={ - :log warning "The Internet connection may be degraded. (Ping result: \ - $WanPingCount/$PingCount)"; + :log warning "The Internet connection may be degraded. (Ping \ + result: $WanPingCount/$PingCount)"; } diff --git a/scripts/v7/ch7-06-if-multiple-conditions.rsc b/scripts/v7/ch7-06-if-multiple-conditions.rsc index 2108ed5..9722d04 100644 --- a/scripts/v7/ch7-06-if-multiple-conditions.rsc +++ b/scripts/v7/ch7-06-if-multiple-conditions.rsc @@ -5,7 +5,7 @@ :put "The current time is : $CurrentTime"; # declare the time of day variable -:local TimeOfDay +:local TimeOfDay; # Check if it's very early :if (($CurrentTime >= 00:00) and ($CurrentTime < 06:00)) do={ diff --git a/scripts/v7/ch7-07-nested-if-statements.rsc b/scripts/v7/ch7-07-nested-if-statements.rsc index 78ab5ca..b060e96 100644 --- a/scripts/v7/ch7-07-nested-if-statements.rsc +++ b/scripts/v7/ch7-07-nested-if-statements.rsc @@ -5,7 +5,7 @@ :put "The current time is : $CurrentTime"; # declare the time of day variable -:local TimeOfDay +:local TimeOfDay; # Check if it's before noon :if ($CurrentTime < 12:00) do={ @@ -13,7 +13,8 @@ # it's before noon, let's see what time of the morning # it is using a nested if-else statement if ($CurrentTime < 06:00) do={ - :set TimeOfDay "It's very early in the morning...shouldn't you be in bed?"; + :set TimeOfDay "It's very early in the morning...shouldn't \ + you be in bed?"; } else={ # it must be between 06:01 and 11:59 to reach here :set TimeOfDay "Good morning!"; diff --git a/scripts/v7/ch7-08-if-else-binary.rsc b/scripts/v7/ch7-08-if-else-binary.rsc index 29fdba4..a01e55e 100644 --- a/scripts/v7/ch7-08-if-else-binary.rsc +++ b/scripts/v7/ch7-08-if-else-binary.rsc @@ -3,12 +3,12 @@ # define WAN interface name :local WanInterfaceName "ether1-WAN"; -# find the interface index -:local InterfaceIndex [/interface/ethernet find name=$WanInterfaceName]; +# find the interface ID +:local InterfaceId [/interface/ethernet find name=$WanInterfaceName]; :local UpDown; -if ([:interface ethernet get $InterfaceIndex]->"running") do={ +if ([:interface ethernet get $InterfaceId]->"running") do={ :set UpDown "up"; } else={ :set UpDown "down"; diff --git a/scripts/v7/ch7-09-if-binary-simplified.rsc b/scripts/v7/ch7-09-if-binary-simplified.rsc index 00a12e2..fb8dbaa 100644 --- a/scripts/v7/ch7-09-if-binary-simplified.rsc +++ b/scripts/v7/ch7-09-if-binary-simplified.rsc @@ -4,10 +4,10 @@ :local WanInterfaceName "ether1-WAN"; # find the interface index -:local InterfaceIndex [/interface/ethernet find name=$WanInterfaceName]; +:local InterfaceId [/interface/ethernet find name=$WanInterfaceName]; :local UpDown "down"; -if ([:interface/ethernet get $InterfaceIndex]->"running") do={ +if ([:interface/ethernet get $InterfaceId]->"running") do={ :set UpDown "up" } diff --git a/scripts/v7/ch8-01-for-basic.rsc b/scripts/v7/ch8-01-for-basic.rsc index cd1b173..5a4a508 100644 --- a/scripts/v7/ch8-01-for-basic.rsc +++ b/scripts/v7/ch8-01-for-basic.rsc @@ -4,7 +4,7 @@ # the 12 times table :for LoopCount from=1 to=5 do={ - :put ("Current loop counter is: $LoopCount"); + :put "Current loop counter is: $LoopCount"; :put ("12 x $LoopCount is: " . (12 * $LoopCount)); } diff --git a/scripts/v7/ch8-02-for-check-web.rsc b/scripts/v7/ch8-02-for-check-web.rsc index 54584ad..1b65b21 100644 --- a/scripts/v7/ch8-02-for-check-web.rsc +++ b/scripts/v7/ch8-02-for-check-web.rsc @@ -12,9 +12,8 @@ :local PingResult [/ping $Site count=3 ]; :if ($PingResult > 0) do { - :put ("\nWeb site $Site reached OK\n"); + :put "\nWeb site $Site reached OK\n"; } else={ - :put ("\nNo response from web site: $Site\n"); + :put "\nNo response from web site: $Site\n"; } -} - +} \ No newline at end of file diff --git a/scripts/v7/ch8-03-for-create-vlan.rsc b/scripts/v7/ch8-03-for-create-vlan.rsc index ae1af48..09cedf1 100644 --- a/scripts/v7/ch8-03-for-create-vlan.rsc +++ b/scripts/v7/ch8-03-for-create-vlan.rsc @@ -8,8 +8,8 @@ :for VlanId from=100 to=150 step=10 do={ :put ("Creating VLAN $VlanId on interface $InterfaceName"); - :local VlanName ("vlan" . $VlanId); - /interface vlan add name=$VlanName vlan-id=$VlanId interface=$InterfaceName; + /interface vlan add name=$VlanName vlan-id=$VlanId \ + interface=$InterfaceName; } diff --git a/scripts/v7/ch9-03-mutiple-args-array.rsc b/scripts/v7/ch9-03-mutiple-args-array.rsc index d0a91aa..8f47b9b 100644 --- a/scripts/v7/ch9-03-mutiple-args-array.rsc +++ b/scripts/v7/ch9-03-mutiple-args-array.rsc @@ -28,7 +28,8 @@ } # data type checks passed, print the interface data - :put "$InterfaceName: IP address = $InterfaceIp, speed = $InterfaceSpeed"; + :put "$InterfaceName: IP address = $InterfaceIp, speed = \ + $InterfaceSpeed"; } # --- end of function --- @@ -37,7 +38,8 @@ $PrintInterfaceAttrsFunc $Args; # Let's call the function with some other values in an array -:set Args { ifname="ether2-LAN"; ifspeed="1000Mbps"; ifip="172.16.1.254/24" }; +:set Args { ifname="ether2-LAN"; ifspeed="1000Mbps"; + ifip="172.16.1.254/24" }; $PrintInterfaceAttrsFunc $Args; # Cleanup global namespace diff --git a/scripts/v7/ch9-06-str-funcs-mod.rsc b/scripts/v7/ch9-06-str-funcs-mod.rsc index 36d424e..76a7b51 100644 --- a/scripts/v7/ch9-06-str-funcs-mod.rsc +++ b/scripts/v7/ch9-06-str-funcs-mod.rsc @@ -16,7 +16,7 @@ # function to remove last char from a string # -# e.g. :local ChoppedVar [$chopStrFunc "string with extra char,"] +# e.g. :local ChoppedVar [$ChopStrFunc "string with extra char,"] # :global ChopStrFunc do={ :return [ :pick $1 0 ( [ :len $1 ] -1 ) ]; diff --git a/scripts/v7/ch9-07-use-str-module.rsc b/scripts/v7/ch9-07-use-str-module.rsc index 00b230d..3664321 100644 --- a/scripts/v7/ch9-07-use-str-module.rsc +++ b/scripts/v7/ch9-07-use-str-module.rsc @@ -1,6 +1,7 @@ # filename: ch9-07-use-str-module.rsc -# import the functions we need and declare the function names we wish to use +# import the functions we need and declare the function +# names we wish to use /import "ch9-06-str-funcs-mod.rsc" :global RemoveSpaceFunc; :global ChopStrFunc;