pls help how to print all profile name with starts with the name FIBR
i have a script but it print only 1
:put ([/ppp profile print as-value where name~“FIBR”] ->1->“name”)
pls help how to print all profile name with starts with the name FIBR
i have a script but it print only 1
:put ([/ppp profile print as-value where name~“FIBR”] ->1->“name”)
You are picking one element from an array, instead you should run foreach loop to go through all the elements of an array.
how can u give me an example pls
You need to find what you are looking for, then get all the data for the ID that find returns.
print should not be used in script.
:foreach Profile in=[/ppp profile find where name~"FIBR"] do={:put [/ppp profile get $Profile]}
Some more clean setup.
/ppp profile
:foreach Profile in=[find where name~"FIBR"] do={
:put [/ppp profile get $Profile]
}
If you like to try this at command line, you need to wrap it in {} (since its more than one line), so:
{
/ppp profile
:foreach Profile in=[find where name~"FIBR"] do={
:put [/ppp profile get $Profile]
}
}
get.. NAME… ![]()
containing “FIBR” (CASE SENSITIVE!!!)
/ppp profile
:foreach profID in=[find where name~"FIBR"] do={
:put [get $profID name]
}
starts with “FIBR” (CASE SENSITIVE!!!)
/ppp profile
:foreach profID in=[find where name~"^FIBR"] do={
:put [get $profID name]
}
Notice:
[get $profID name]
or
([get $profID]->“name”)
on this case are equivalents, but the first is more readable
Hmm
I hoped that this should work, but it does not:
name~"(?i)fibr"
Did try this as well, but does not work.
name~"(\?i)fibr"
MikroTik use syntax compatible only with POSIX RegEx, but without “Character Classes” and is not present support for other platform RegEx syntax
start with
name~“[1][Ii][Bb][Rr]”
or
name~“^(F|f)(I|i)(B|b)(R|r)”
contain
name~“[Ff][Ii][Bb][Rr]”
or
name~“(F|f)(I|i)(B|b)(R|r)”
Ff ↩︎
MT does not handle upper/lower case very good.
Missing toupper/tolower (?i) +++
missing also RegEx on :find… ![]()
thanks for the help it works. but how can i send this through sms. not working
/ppp profile
:foreach profID in=[find where name~“FIBR”] do={
:log warning message=[get $profID name]
:local plan [get $profID name]
}
:log warning message=“send to sms”
/tool sms send phone-number=056698885 message=“$plan”
}
}
} on-error={:log error message=“script failed…”}
The script you write can not work because :local variables inside “{” are lost at first “}” and if global is used, return only the last profile with “FIBR” inside
You first try on terminal to see if the machine send SMS?
/tool sms send phone-number=056698885 message="test"
Probably you need something like this:
One SMS for each profile containing FIBR
/ppp profile
:foreach profID in=[find where name~"FIBR"] do={
:log warning message="send $[get $profID name] to SMS"
/tool sms send phone-number=056698885 message=[/ppp profile get $profID name]
}
Only one unique SMS with all profiles that containing FIBR
(single SMS is max 160 characters!!!)
{
/ppp profile
:local allprofiles ""
:foreach profID in=[find where name~"FIBR"] do={
:if ($allprofiles="") do={ :set allprofiles [get $profID name] } else={ :set allprofiles "$allprofiles,$[get $profID name]" }
}
:log warning message="send $allprofiles to SMS"
/tool sms send phone-number=056698885 message=$allprofiles
}
it works. thank u very much sir rextended
lastly how to pick it like for example i want to remove the name FIBR when i recieved the sms
like for example
instead of
FIBR 12 10MBPS
FIBR 15 15MBPS
FIBR 17 17MBPS
they reiceved the message of
12 10MBPS
15 15MBPS
17 17MBPS
please be more clear, you want remove FIBR on COMMENTed profile, or INSIDE SMS?
on sms sir
Removing "FIBR " (and space):
One SMS for each profile containing FIBR and removing "FIBR " on SMS
/ppp profile
:foreach profID in=[find where name~"FIBR"] do={
:local profname [get $profID name]
# 5 is the lenght of prefix FIBR including space
:set profname [:pick $profname ([:find $profname "FIBR "] + 5) [:len $profname]]
:log warning message="send $profname to SMS"
/tool sms send phone-number=056698885 message=$profname
}
Only one unique SMS with all profiles that containing FIBR and removing "FIBR " on SMS
(single SMS is max 160 characters!!!)
{
/ppp profile
:local allprofiles ""
:foreach profID in=[find where name~"FIBR"] do={
:local profname [get $profID name]
# 5 is the lenght of prefix FIBR including space
:set profname [:pick $profname ([:find $profname "FIBR "] + 5) [:len $profname]]
:if ($allprofiles="") do={ :set allprofiles [get $profID name] } else={ :set allprofiles "$allprofiles,$profname" }
}
:log warning message="send $allprofiles to SMS"
/tool sms send phone-number=056698885 message=$allprofiles
}
thanks sir ,
how about not to include my current profile in sms
example my current profile is 15 15MBPS
12 10MBPS
15 15MBPS (remove this)
17 17MBPS
explain better, and where I can see the current profile?
if my subscriber have a plan of 5MBPS in ppp secret profile
and text 9. i want reply of my system to my subscriber all profile~FIBR but not included the current plan of my subscriber
:foreach i in=[/tool sms inbox find where message=“9”] do={
:local smsPhone [/tool sms inbox get $i phone];
:local old [ :pick $smsPhone 3 14 ]
:if ([/ppp secret find where profile~“FIBR” ipv6-routes=“$old” && comment>“-4”]) do={
:local sname [/ppp secret get [find ipv6-routes=“$old”] name];
:local profile [/ppp secret get [find ipv6-routes=“$old”] profile];
:local prof1 [ :pick $profile 0 4 ];
:local prof2 [ :pick $profile 5 9 ];
:local prof3 [ :pick $profile 10 17 ];
:local allprofiles
/ppp profile
:foreach profID in=[find where name~“FIBR”] do={
:local profname [get $profID name]
:set profname [:pick $profname ([:find $profname] + 5) [:len $profname]]
:if ($allprofiles=“”) do={ :set allprofiles [get $profID name] } else={ :set allprofiles “$allprofiles\r\n$profname” }
}
/tool sms send phone=“$old” message="UR CURRENT PLAN is:
$prof1 $prof2 $prof3
PLAN AVAILABLE:$allprofiles
-$identity"
}
you can replace
foreach profID in=[find where name~“FIBR”] do={
with something like
foreach profID in=[find where name~“FIBR” and name!=$currentprofilename] do={
thank you sir for your help
one more sir
how can i order it from lower to higher price
i received like this
20 20MBPS
10 `10MBPS
30 30MBPS
5 5MBPS