publish copy updates

This commit is contained in:
Wifinigel 2023-03-06 20:56:48 +00:00
parent 4548f7c5c1
commit 8a3419b536
22 changed files with 63 additions and 48 deletions

View file

@ -4,6 +4,6 @@
:for Number from=1 to=10 do={ :for Number from=1 to=10 do={
:local Result ($Number * $MULTIPLIER) :local Result ($Number * $MULTIPLIER)
:put ("This is an unusually long line. Here is the result $Number times \ :put ("This is an unusually long line. Here is the result $Number \
$MULTIPLIER is: $Result") times $MULTIPLIER is: $Result")
} }

View file

@ -4,6 +4,6 @@
:for Number from=1 to=10 do={ :for Number from=1 to=10 do={
:local Result ($Number * $MULTIPLIER); :local Result ($Number * $MULTIPLIER);
:put ("This is an unusually long line. Here is the result $Number times \ :put ("This is an unusually long line. Here is the result $Number \
$MULTIPLIER is: $Result"); times $MULTIPLIER is: $Result");
} }

View file

@ -5,6 +5,6 @@
:local GlobalScopeVar "I'm in the global scope!"; :local GlobalScopeVar "I'm in the global scope!";
# Let's print it out # Let's print it out
:put ("Global variable contents = $GlobalScopeVar"); :put ("Global scope variable contents = $GlobalScopeVar");
# ---- global scope end ---- # ---- global scope end ----

View file

@ -22,10 +22,10 @@ if ( [:typeof $WanInterfaces] != "array") do={
# Let's step through the interfaces in the array # Let's step through the interfaces in the array
# and print out their operation status # and print out their operation status
:foreach WanInterface in=$WanInterfaces do={ :foreach WanInterface in=$WanInterfaces do={
:local InterfaceIndex [/interface ethernet find name=$WanInterface]; :local InterfaceId [/interface ethernet find name=$WanInterface];
:local UpDown "down"; :local UpDown "down";
if ([:interface ethernet get $InterfaceIndex]->"running") do={ if ([:interface ethernet get $InterfaceId]->"running") do={
:set UpDown "up" :set UpDown "up"
} }

View file

@ -11,24 +11,27 @@
# define a target web site # define a target web site
:local WebSite "www.google.com"; :local WebSite "www.google.com";
# run a while loop until one minute interval expired # run a while loop until one minute interval has expired
:while ( [/system clock get time] < $EndTime ) do={ :while ( [/system clock get time] < $EndTime ) do={
:put "Getting web page from $WebSite"; :put "Getting web page from $WebSite";
# fetch a page from web site # fetch a page from web site
:local FetchResult [/tool fetch url=("https://$WebSite") mode=https \ :local FetchResult;
http-method=get as-value keep-result=no]; :local TimeTaken [:time {
:set FetchResult [/tool fetch url=("https://$WebSite") \
mode=https http-method=get as-value keep-result=no];
}];
if ($FetchResult->"status" = "finished") do={ if ($FetchResult->"status" = "finished") do={
# print out how long page retrieval took (if successful) # print out how long page retrieval took (if successful)
:local FetchDuration ($FetchResult->"duration"); :put "Web page fetch time: $TimeTaken secs";
:put "Web page fetch time: $FetchDuration secs";
} else={ } else={
# print failure message if fetch failed
:put "Web page fetch failed"; :put "Web page fetch failed";
} }
# pause for 5 seconds # pause for 5 seconds
:delay 5; :delay 5;
} }
:put "One minute period has ended!"

View file

@ -6,8 +6,8 @@
# --- start of function --- # --- start of function ---
:global MacColonRemoveFunc do={ :global MacColonRemoveFunc do={
:local TidyMac ""; :local TidyMac "";
for i from=0 to=([:len $1]-1) do={ for CharNumber from=0 to=([:len $1]-1) do={
:local TmpValue [:pick $1 $i]; :local TmpValue [:pick $1 $CharNumber];
:if ($TmpValue !=":") do={ :set TidyMac "$TidyMac$TmpValue" } :if ($TmpValue !=":") do={ :set TidyMac "$TidyMac$TmpValue" }
} }
:return $TidyMac; :return $TidyMac;

View file

@ -23,7 +23,8 @@
} }
# data type checks passed, print the interface data # 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 --- # --- end of function ---

View file

@ -5,10 +5,12 @@
# --- start of function --- # --- start of function ---
:global PrintInterfaceAttrsFunc do={ :global PrintInterfaceAttrsFunc do={
# verify arg is correct type
if ([:typeof $1] != "array") do={ if ([:typeof $1] != "array") do={
:error "Function argument is not an array!"; :error "Function argument is not an array!";
} }
# extract values from array passed as arg
:local Args $1; :local Args $1;
:local InterfaceName ($Args->"ifname"); :local InterfaceName ($Args->"ifname");
:local InterfaceSpeed ($Args->"ifspeed"); :local InterfaceSpeed ($Args->"ifspeed");
@ -34,12 +36,13 @@
# --- end of function --- # --- end of function ---
# Let's call the function with some sample values in an array # Let's call the function with some sample values in an array
:local Args { ifname="WAN1"; ifspeed="100Mbps"; :local Args { ifname="WAN1"; ifspeed="100Mbps"; \
ifip="192.168.99.1/24" }; ifip="192.168.99.1/24" };
$PrintInterfaceAttrsFunc $Args; $PrintInterfaceAttrsFunc $Args;
# Let's call the function with some other values in an array # 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; $PrintInterfaceAttrsFunc $Args;
# Cleanup global namespace # Cleanup global namespace

View file

@ -6,8 +6,8 @@
# #
:global RemoveSpaceFunc do={ :global RemoveSpaceFunc do={
:local NewName "" :local NewName ""
for i from=0 to=([:len $1]-1) do={ for CharNumber from=0 to=([:len $1]-1) do={
:local Tmp [:pick $1 $i] :local Tmp [:pick $1 $CharNumber]
:if ($Tmp !=" ") do={ :set NewName "$NewName$Tmp" } :if ($Tmp !=" ") do={ :set NewName "$NewName$Tmp" }
} }
:return $NewName :return $NewName

View file

@ -6,8 +6,8 @@
# #
:global RemoveSpaceFunc do={ :global RemoveSpaceFunc do={
:local NewName "" :local NewName ""
for i from=0 to=([:len $1]-1) do={ for CharNumber from=0 to=([:len $1]-1) do={
:local Tmp [:pick $1 $i] :local Tmp [:pick $1 $CharNumber]
:if ($Tmp !=" ") do={ :set NewName "$NewName$Tmp" } :if ($Tmp !=" ") do={ :set NewName "$NewName$Tmp" }
} }
:return $NewName :return $NewName

View file

@ -1,6 +1,6 @@
# filename: ch9-07-use-str-module.rsc # filename: ch9-07-use-str-module.rsc
# import the functions we need and declare the function # import the functions we need and declare the functions
# names we wish to use # names we wish to use
/import "ch9-06-str-funcs-mod.rsc" /import "ch9-06-str-funcs-mod.rsc"
:global RemoveSpaceFunc; :global RemoveSpaceFunc;

View file

@ -4,6 +4,6 @@
:for Number from=1 to=10 do={ :for Number from=1 to=10 do={
:local Result ($Number * $MULTIPLIER) :local Result ($Number * $MULTIPLIER)
:put ("This is an unusually long line. Here is the result $Number times \ :put ("This is an unusually long line. Here is the result \
$MULTIPLIER is: $Result") $Number times $MULTIPLIER is: $Result")
} }

View file

@ -4,6 +4,6 @@
:for Number from=1 to=10 do={ :for Number from=1 to=10 do={
:local Result ($Number * $MULTIPLIER); :local Result ($Number * $MULTIPLIER);
:put ("This is an unusually long line. Here is the result $Number times \ :put ("This is an unusually long line. Here is the result $Number \
$MULTIPLIER is: $Result"); times $MULTIPLIER is: $Result");
} }

View file

@ -5,6 +5,6 @@
:local GlobalScopeVar "I'm in the global scope!"; :local GlobalScopeVar "I'm in the global scope!";
# Let's print it out # Let's print it out
:put ("Global variable contents = $GlobalScopeVar"); :put ("Global scope variable contents = $GlobalScopeVar");
# ---- global scope end ---- # ---- global scope end ----

View file

@ -22,10 +22,10 @@ if ( [:typeof $WanInterfaces] != "array") do={
# Let's step through the interfaces in the array # Let's step through the interfaces in the array
# and print out their operation status # and print out their operation status
:foreach WanInterface in=$WanInterfaces do={ :foreach WanInterface in=$WanInterfaces do={
:local InterfaceIndex [/interface/ethernet find name=$WanInterface]; :local InterfaceId [/interface/ethernet find name=$WanInterface];
:local UpDown "down"; :local UpDown "down";
if ([:interface/ethernet get $InterfaceIndex]->"running") do={ if ([:interface/ethernet get $InterfaceId]->"running") do={
:set UpDown "up" :set UpDown "up"
} }

View file

@ -3,7 +3,7 @@
# script to report page load time of google.com # script to report page load time of google.com
# get the current time # get the current time
:local CurrentTime [/system/clock get time]; :local CurrentTime [/system clock get time];
# calculate the time in 1 minute # calculate the time in 1 minute
:local EndTime ($CurrentTime + 00:01:00); :local EndTime ($CurrentTime + 00:01:00);
@ -11,24 +11,28 @@
# define a target web site # define a target web site
:local WebSite "www.google.com"; :local WebSite "www.google.com";
# run a while loop until one minute interval expired # run a while loop until one minute interval has expired
:while ( [/system/clock get time] < $EndTime ) do={ :while ( [/system/clock get time] < $EndTime ) do={
:put "Getting web page from $WebSite"; :put "Getting web page from $WebSite";
# fetch a page from web site # fetch a page from web site
:local FetchResult [/tool fetch url=("https://$WebSite") mode=https \ :local FetchResult;
http-method=get as-value keep-result=no]; :local TimeTaken [:time {
:set FetchResult [/tool fetch url=("https://$WebSite") \
mode=https http-method=get as-value keep-result=no];
}];
if ($FetchResult->"status" = "finished") do={ if ($FetchResult->"status" = "finished") do={
# print out how long page retrieval took (if successful) # print out how long page retrieval took (if successful)
:local FetchDuration ($FetchResult->"duration"); :put "Web page fetch time: $TimeTaken secs";
:put "Web page fetch time: $FetchDuration secs";
} else={ } else={
# print failure message if fetch failed
:put "Web page fetch failed"; :put "Web page fetch failed";
} }
# pause for 5 seconds # pause for 5 seconds
:delay 5; :delay 5;
} }
:put "One minute period has ended!"

View file

@ -6,8 +6,8 @@
# --- start of function --- # --- start of function ---
:global MacColonRemoveFunc do={ :global MacColonRemoveFunc do={
:local TidyMac ""; :local TidyMac "";
for i from=0 to=([:len $1]-1) do={ for CharNumber from=0 to=([:len $1]-1) do={
:local TmpValue [:pick $1 $i]; :local TmpValue [:pick $1 $CharNumber];
:if ($TmpValue !=":") do={ :set TidyMac "$TidyMac$TmpValue" } :if ($TmpValue !=":") do={ :set TidyMac "$TidyMac$TmpValue" }
} }
:return $TidyMac; :return $TidyMac;

View file

@ -23,7 +23,8 @@
} }
# data type checks passed, print the interface data # 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 --- # --- end of function ---

View file

@ -5,10 +5,12 @@
# --- start of function --- # --- start of function ---
:global PrintInterfaceAttrsFunc do={ :global PrintInterfaceAttrsFunc do={
# verify arg is correct type
if ([:typeof $1] != "array") do={ if ([:typeof $1] != "array") do={
:error "Function argument is not an array!"; :error "Function argument is not an array!";
} }
# extract values from array passed as arg
:local Args $1; :local Args $1;
:local InterfaceName ($Args->"ifname"); :local InterfaceName ($Args->"ifname");
:local InterfaceSpeed ($Args->"ifspeed"); :local InterfaceSpeed ($Args->"ifspeed");
@ -34,11 +36,12 @@
# --- end of function --- # --- end of function ---
# Let's call the function with some sample values in an array # 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; $PrintInterfaceAttrsFunc $Args;
# Let's call the function with some other values in an array # Let's call the function with some other values in an array
:set Args { ifname="ether2-LAN"; ifspeed="1000Mbps"; :set Args { ifname="ether2-LAN"; ifspeed="1000Mbps"; \
ifip="172.16.1.254/24" }; ifip="172.16.1.254/24" };
$PrintInterfaceAttrsFunc $Args; $PrintInterfaceAttrsFunc $Args;

View file

@ -6,8 +6,8 @@
# #
:global RemoveSpaceFunc do={ :global RemoveSpaceFunc do={
:local NewName "" :local NewName ""
for i from=0 to=([:len $1]-1) do={ for CharNumber from=0 to=([:len $1]-1) do={
:local Tmp [:pick $1 $i] :local Tmp [:pick $1 $CharNumber]
:if ($Tmp !=" ") do={ :set NewName "$NewName$Tmp" } :if ($Tmp !=" ") do={ :set NewName "$NewName$Tmp" }
} }
:return $NewName :return $NewName

View file

@ -6,8 +6,8 @@
# #
:global RemoveSpaceFunc do={ :global RemoveSpaceFunc do={
:local NewName "" :local NewName ""
for i from=0 to=([:len $1]-1) do={ for CharNumber from=0 to=([:len $1]-1) do={
:local Tmp [:pick $1 $i] :local Tmp [:pick $1 $CharNumber]
:if ($Tmp !=" ") do={ :set NewName "$NewName$Tmp" } :if ($Tmp !=" ") do={ :set NewName "$NewName$Tmp" }
} }
:return $NewName :return $NewName

View file

@ -1,6 +1,6 @@
# filename: ch9-07-use-str-module.rsc # filename: ch9-07-use-str-module.rsc
# import the functions we need and declare the function # import the functions we need and declare the functions
# names we wish to use # names we wish to use
/import "ch9-06-str-funcs-mod.rsc" /import "ch9-06-str-funcs-mod.rsc"
:global RemoveSpaceFunc; :global RemoveSpaceFunc;