I’m tyring to figure out how to break a loop when a condition is met. I have the following script working the way I’d like:
:global source [:tostr [/system resource usb get [/system resource usb find ports=0]]]
:local start ([:find $source “device-id=”] + [:len “device-id=”]); :local end [:find $source “,” $start]; :global deviceID [:pick $source $start $end]; :put $deviceID;
:global content [/file get [/file find name=test.txt] contents] ;
:global contentLen [ :len $content ] ;
:global lineEnd 0;
:global line “”;
:global lastEnd 0;
:do {
:set lineEnd [:find $content “\r\n” $lastEnd ] ;
:set line [:pick $content $lastEnd $lineEnd] ;
:set lastEnd ( $lineEnd + 2 ) ;
:local tmpArray [:toarray $line];
:if ([:pick $tmpArray 0] =$deviceID) do={
/interface ppp-client
add add-default-route=yes allow=pap,chap,mschap1,mschap2 comment=“”
data-channel=[:pick $tmpArray 2] dial-command=ATDT dial-on-demand=no disabled=no
info-channel=[:pick $tmpArray 3] keepalive-timeout=30 max-mru=1500 max-mtu=1500 modem-init=
“” mrru=disabled name=ppp-out1 null-modem=no password=“” phone=[:pick $tmpArray 1] pin=
“” port=usb profile=default use-peer-dns=yes user=“”;
}
} while ($lineEnd < $contentLen)
However I’d like it so that if there are no matches from tmpArray 0 from the test.txt file. A default ppp-client is added. If there is a match the default ppp-client is not added.
Thanks,